diff --git a/assembly/release-base.xml b/assembly/release-base.xml index 2a82af8b2e9cd..3c94d6f490aa7 100644 --- a/assembly/release-base.xml +++ b/assembly/release-base.xml @@ -27,6 +27,11 @@ / + + NOTICE.txt + / + + config/ignite-log4j.xml /config diff --git a/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java index fdd369b15a293..cf9aee219bc80 100644 --- a/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java +++ b/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java @@ -61,6 +61,8 @@ public static IgniteConfiguration configuration() throws IgniteException { cfg.setDeploymentMode(SHARED); cfg.setPeerClassLoadingEnabled(true); + cfg.setClientConnectionConfiguration(new ClientConnectionConfiguration()); + OptimizedMarshaller marsh = new OptimizedMarshaller(); marsh.setRequireSerializable(false); diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientPortableArgumentTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientPortableArgumentTask.java deleted file mode 100644 index 82cafda3e7c6d..0000000000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientPortableArgumentTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.client; - -import org.apache.ignite.portables.*; - -import java.util.*; - -/** - * Task where argument and result are {@link ClientTestPortable}. - */ -public class ClientPortableArgumentTask extends TaskSingleJobSplitAdapter { - /** {@inheritDoc} */ - @Override protected Object executeJob(int gridSize, Object arg) { - Collection args = (Collection)arg; - - Iterator it = args.iterator(); - - assert args.size() == 2 : args.size(); - - boolean expPortable = (Boolean)it.next(); - - ClientTestPortable p; - - if (expPortable) { - PortableObject obj = (PortableObject)it.next(); - - p = obj.deserialize(); - } - else - p = (ClientTestPortable)it.next(); - - assert p != null; - - return new ClientTestPortable(p.i + 1, true); - } -} diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientPutPortableTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientPutPortableTask.java deleted file mode 100644 index a1452cd4dd595..0000000000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientPutPortableTask.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.client; - -import org.apache.ignite.*; -import org.apache.ignite.resources.*; - -/** - * Task creates portable object and puts it in cache. - */ -public class ClientPutPortableTask extends TaskSingleJobSplitAdapter { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override protected Object executeJob(int gridSize, Object arg) { - String cacheName = (String)arg; - - IgniteCache cache = ignite.jcache(cacheName); - - ClientTestPortable p = new ClientTestPortable(100, true); - - cache.put(1, p); - - return true; - } -} diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortable.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortable.java deleted file mode 100644 index 07d61776982ae..0000000000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortable.java +++ /dev/null @@ -1,490 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.client; - -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; - -import java.io.*; -import java.util.*; - -/** - * Test portable object. - */ -@SuppressWarnings("PublicField") -public class ClientTestPortable implements PortableMarshalAware, Serializable { - /** */ - public byte b; - - /** */ - public byte bRaw; - - /** */ - public short s; - - /** */ - public short sRaw; - - /** */ - public int i; - - /** */ - public int iRaw; - - /** */ - public long l; - - /** */ - public long lRaw; - - /** */ - public float f; - - /** */ - public float fRaw; - - /** */ - public double d; - - /** */ - public double dRaw; - - /** */ - public char c; - - /** */ - public char cRaw; - - /** */ - public boolean bool; - - /** */ - public boolean boolRaw; - - /** */ - public String str; - - /** */ - public String strRaw; - - /** */ - public UUID uuid; - - /** */ - public UUID uuidRaw; - - /** */ - public Date date; - - /** */ - public Date dateRaw; - - /** */ - public TestEnum e; - - /** */ - public TestEnum eRaw; - - /** */ - public byte[] bArr; - - /** */ - public byte[] bArrRaw; - - /** */ - public short[] sArr; - - /** */ - public short[] sArrRaw; - - /** */ - public int[] iArr; - - /** */ - public int[] iArrRaw; - - /** */ - public long[] lArr; - - /** */ - public long[] lArrRaw; - - /** */ - public float[] fArr; - - /** */ - public float[] fArrRaw; - - /** */ - public double[] dArr; - - /** */ - public double[] dArrRaw; - - /** */ - public char[] cArr; - - /** */ - public char[] cArrRaw; - - /** */ - public boolean[] boolArr; - - /** */ - public boolean[] boolArrRaw; - - /** */ - public String[] strArr; - - /** */ - public String[] strArrRaw; - - /** */ - public UUID[] uuidArr; - - /** */ - public UUID[] uuidArrRaw; - - /** */ - public Date[] dateArr; - - /** */ - public Date[] dateArrRaw; - - /** */ - public TestEnum[] eArr; - - /** */ - public TestEnum[] eArrRaw; - - /** */ - public Object[] objArr; - - /** */ - public Object[] objArrRaw; - - /** */ - public Collection col; - - /** */ - public Collection colRaw; - - /** */ - public Map map; - - /** */ - public Map mapRaw; - - /** */ - public ClientTestPortable portable1; - - /** */ - public ClientTestPortable portable2; - - /** */ - public ClientTestPortable portableRaw1; - - /** */ - public ClientTestPortable portableRaw2; - - /** - */ - public ClientTestPortable() { - // No-op. - } - - /** - * @param val Value. - * @param createInner If {@code true} creates nested object. - */ - public ClientTestPortable(int val, boolean createInner) { - b = (byte)val; - bRaw = (byte)(val + 1); - - s = (short)val; - sRaw = (short)(val + 1); - - i = val; - iRaw = i + 1; - - l = val; - lRaw = i + 1; - - f = val + 0.5f; - fRaw = f + 1; - - d = val + 0.5f; - dRaw = d + 1; - - c = (char)val; - cRaw = (char)(val + 1); - - bool = true; - boolRaw = false; - - str = String.valueOf(i); - strRaw = String.valueOf(iRaw); - - uuid = new UUID(i, i); - uuidRaw = new UUID(iRaw, iRaw); - - date = new Date(i); - dateRaw = new Date(iRaw); - - e = enumValue(i); - eRaw = enumValue(iRaw); - - bArr = new byte[]{b, (byte)(b + 1)}; - bArrRaw = new byte[]{bRaw, (byte)(bRaw + 1)}; - - sArr = new short[]{s, (short)(s + 1)}; - sArrRaw = new short[]{sRaw, (short)(sRaw + 1)}; - - iArr = new int[]{i, i + 1}; - iArrRaw = new int[]{iRaw, iRaw + 1}; - - lArr = new long[]{l, l + 1}; - lArrRaw = new long[]{lRaw, lRaw + 1}; - - fArr = new float[]{f, f + 1}; - fArrRaw = new float[]{fRaw, fRaw + 1}; - - dArr = new double[]{d, d + 1}; - dArrRaw = new double[]{dRaw, dRaw + 1}; - - cArr = new char[]{c, (char)(c + 1)}; - cArrRaw = new char[]{cRaw, (char)(cRaw + 1)}; - - boolArr = new boolean[]{true, true}; - boolArrRaw = new boolean[]{true, true}; - - strArr = new String[]{str, str + "1"}; - strArrRaw = new String[]{strRaw, strRaw + "1"}; - - uuidArr = new UUID[]{uuid, new UUID(uuid.getMostSignificantBits() + 1, uuid.getLeastSignificantBits() + 1)}; - uuidArrRaw = new UUID[]{uuidRaw, - new UUID(uuidRaw.getMostSignificantBits() + 1, uuidRaw.getLeastSignificantBits() + 1)}; - - dateArr = new Date[]{date, new Date(date.getTime() + 1)}; - dateArrRaw = new Date[]{dateRaw, new Date(dateRaw.getTime() + 1)}; - - eArr = new TestEnum[]{enumValue(i), enumValue(i + 1)}; - eArrRaw = new TestEnum[]{enumValue(iRaw), enumValue(iRaw + 1)}; - - objArr = new Object[]{uuid, new UUID(uuid.getMostSignificantBits() + 1, uuid.getLeastSignificantBits() + 1)}; - objArrRaw = new Object[]{uuidRaw, - new UUID(uuidRaw.getMostSignificantBits() + 1, uuidRaw.getLeastSignificantBits() + 1)}; - - col = Arrays.asList(str, str + "1"); - colRaw = Arrays.asList(strRaw, strRaw + "1"); - - map = new HashMap<>(); - map.put(1, str); - map.put(2, str + "1"); - - mapRaw = new HashMap<>(); - mapRaw.put(1, strRaw); - mapRaw.put(2, strRaw + "1"); - - if (createInner) { - portable1 = new ClientTestPortable(val + 1, false); - portable2 = portable1; - - portableRaw1 = new ClientTestPortable(val + 2, false); - portableRaw2 = portableRaw1; - } - } - - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - writer.writeByte("_b", b); - writer.writeShort("_s", s); - writer.writeInt("_i", i); - writer.writeLong("_l", l); - writer.writeFloat("_f", f); - writer.writeDouble("_d", d); - writer.writeChar("_c", c); - writer.writeBoolean("_bool", bool); - writer.writeString("_str", str); - writer.writeUuid("_uuid", uuid); - writer.writeDate("_date", date); - writer.writeEnum("_enum", e); - writer.writeByteArray("_bArr", bArr); - writer.writeShortArray("_sArr", sArr); - writer.writeIntArray("_iArr", iArr); - writer.writeLongArray("_lArr", lArr); - writer.writeFloatArray("_fArr", fArr); - writer.writeDoubleArray("_dArr", dArr); - writer.writeCharArray("_cArr", cArr); - writer.writeBooleanArray("_boolArr", boolArr); - writer.writeStringArray("_strArr", strArr); - writer.writeUuidArray("_uuidArr", uuidArr); - writer.writeDateArray("_dateArr", dateArr); - writer.writeEnumArray("_eArr", eArr); - writer.writeObjectArray("_objArr", objArr); - writer.writeCollection("_col", col); - writer.writeMap("_map", map); - writer.writeObject("_portable1", portable1); - writer.writeObject("_portable2", portable2); - - PortableRawWriter raw = writer.rawWriter(); - - raw.writeByte(bRaw); - raw.writeShort(sRaw); - raw.writeInt(iRaw); - raw.writeLong(lRaw); - raw.writeFloat(fRaw); - raw.writeDouble(dRaw); - raw.writeChar(cRaw); - raw.writeBoolean(boolRaw); - raw.writeString(strRaw); - raw.writeUuid(uuidRaw); - raw.writeDate(dateRaw); - raw.writeEnum(eRaw); - raw.writeByteArray(bArrRaw); - raw.writeShortArray(sArrRaw); - raw.writeIntArray(iArrRaw); - raw.writeLongArray(lArrRaw); - raw.writeFloatArray(fArrRaw); - raw.writeDoubleArray(dArrRaw); - raw.writeCharArray(cArrRaw); - raw.writeBooleanArray(boolArrRaw); - raw.writeStringArray(strArrRaw); - raw.writeUuidArray(uuidArrRaw); - raw.writeDateArray(dateArrRaw); - raw.writeEnumArray(eArrRaw); - raw.writeObjectArray(objArrRaw); - raw.writeCollection(colRaw); - raw.writeMap(mapRaw); - raw.writeObject(portableRaw1); - raw.writeObject(portableRaw2); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - b = reader.readByte("_b"); - s = reader.readShort("_s"); - i = reader.readInt("_i"); - l = reader.readLong("_l"); - f = reader.readFloat("_f"); - d = reader.readDouble("_d"); - c = reader.readChar("_c"); - bool = reader.readBoolean("_bool"); - str = reader.readString("_str"); - uuid = reader.readUuid("_uuid"); - date = reader.readDate("_date"); - e = reader.readEnum("_enum", TestEnum.class); - bArr = reader.readByteArray("_bArr"); - sArr = reader.readShortArray("_sArr"); - iArr = reader.readIntArray("_iArr"); - lArr = reader.readLongArray("_lArr"); - fArr = reader.readFloatArray("_fArr"); - dArr = reader.readDoubleArray("_dArr"); - cArr = reader.readCharArray("_cArr"); - boolArr = reader.readBooleanArray("_boolArr"); - strArr = reader.readStringArray("_strArr"); - uuidArr = reader.readUuidArray("_uuidArr"); - dateArr = reader.readDateArray("_dateArr"); - eArr = reader.readEnumArray("_eArr", TestEnum.class); - objArr = reader.readObjectArray("_objArr"); - col = reader.readCollection("_col"); - map = reader.readMap("_map"); - portable1 = (ClientTestPortable)reader.readObject("_portable1"); - portable2 = (ClientTestPortable)reader.readObject("_portable2"); - - PortableRawReader raw = reader.rawReader(); - - bRaw = raw.readByte(); - sRaw = raw.readShort(); - iRaw = raw.readInt(); - lRaw = raw.readLong(); - fRaw = raw.readFloat(); - dRaw = raw.readDouble(); - cRaw = raw.readChar(); - boolRaw = raw.readBoolean(); - strRaw = raw.readString(); - uuidRaw = raw.readUuid(); - dateRaw = raw.readDate(); - eRaw = raw.readEnum(TestEnum.class); - bArrRaw = raw.readByteArray(); - sArrRaw = raw.readShortArray(); - iArrRaw = raw.readIntArray(); - lArrRaw = raw.readLongArray(); - fArrRaw = raw.readFloatArray(); - dArrRaw = raw.readDoubleArray(); - cArrRaw = raw.readCharArray(); - boolArrRaw = raw.readBooleanArray(); - strArrRaw = raw.readStringArray(); - uuidArrRaw = raw.readUuidArray(); - dateArrRaw = raw.readDateArray(); - eArrRaw = raw.readEnumArray(TestEnum.class); - objArrRaw = raw.readObjectArray(); - colRaw = raw.readCollection(); - mapRaw = raw.readMap(); - portableRaw1 = (ClientTestPortable)raw.readObject(); - portableRaw2 = (ClientTestPortable)raw.readObject(); - } - - /** - * @param idx Value index. - * @return Enum value. - */ - static TestEnum enumValue(int idx) { - return TestEnum.values()[idx % TestEnum.values().length]; - } - - /** - * Test enum. - */ - private enum TestEnum { - /** */ - VAL1, - - /** */ - VAL2, - - /** */ - VAl3, - - /** */ - VAL4, - - /** */ - VAL5, - - /** */ - VAL6, - - /** */ - VAL7, - - /** */ - VAL8, - - /** */ - VAL9, - - /** */ - VAL10 - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(ClientTestPortable.class, this); - } -} diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortableAffinityKeyTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortableAffinityKeyTask.java deleted file mode 100644 index cde3a0deeeb00..0000000000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortableAffinityKeyTask.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.client; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.portables.*; -import org.apache.ignite.resources.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * Task used to test portable affinity key. - */ -public class ClientTestPortableAffinityKeyTask extends ComputeTaskAdapter { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Nullable @Override public Map map(List clusterNodes, - @Nullable final Object arg) { - for (ClusterNode node : clusterNodes) { - if (node.isLocal()) - return Collections.singletonMap(new ComputeJobAdapter() { - @Override public Object execute() { - return executeJob(arg); - } - }, node); - } - - throw new IgniteException("Failed to find local node in task topology: " + clusterNodes); - } - - /** {@inheritDoc} */ - @Nullable @Override public Boolean reduce(List results) { - return results.get(0).getData(); - } - - /** - * @param arg Argument. - * @return Execution result. - * @throws IgniteException If failed. - */ - protected Boolean executeJob(Object arg) throws IgniteException { - Collection args = (Collection)arg; - - Iterator it = args.iterator(); - - assert args.size() == 3 : args.size(); - - PortableObject obj = (PortableObject)it.next(); - - String cacheName = (String)it.next(); - - String expAffKey = (String)it.next(); - - Object affKey = ignite.cache(cacheName).affinity().affinityKey(obj); - - if (!expAffKey.equals(affKey)) - throw new IgniteException("Unexpected affinity key: " + affKey); - - if (!ignite.cache(cacheName).affinity().mapKeyToNode(obj).isLocal()) - throw new IgniteException("Job is not run on primary node."); - - return true; - } -} diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestRestServer.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTestRestServer.java index fbe3dda20a8a5..017888f11572f 100644 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestRestServer.java +++ b/modules/clients/src/test/java/org/apache/ignite/client/ClientTestRestServer.java @@ -267,6 +267,12 @@ private static class TestParser extends GridTcpRestParser { /** */ private final GridClientMarshaller marsh = new GridClientOptimizedMarshaller(); + /** + */ + public TestParser() { + super(false); + } + /** {@inheritDoc} */ @Override protected GridClientMarshaller marshaller(GridNioSession ses) { return marsh; diff --git a/modules/clients/src/test/java/org/apache/ignite/client/integration/ClientAbstractMultiNodeSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/integration/ClientAbstractMultiNodeSelfTest.java index 6d5afd58f80ff..987e0e7471319 100644 --- a/modules/clients/src/test/java/org/apache/ignite/client/integration/ClientAbstractMultiNodeSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/client/integration/ClientAbstractMultiNodeSelfTest.java @@ -31,9 +31,9 @@ import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.resources.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; @@ -739,7 +739,7 @@ private static class TestTask extends ComputeTaskSplitAdapter { @SuppressWarnings("unchecked") private static class TestCommunicationSpi extends TcpCommunicationSpi { /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { checkSyncFlags((GridIoMessage)msg); diff --git a/modules/clients/src/test/java/org/apache/ignite/client/integration/ClientAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/integration/ClientAbstractSelfTest.java index de5b0e948e0e5..eb538214bd349 100644 --- a/modules/clients/src/test/java/org/apache/ignite/client/integration/ClientAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/client/integration/ClientAbstractSelfTest.java @@ -434,7 +434,7 @@ public void testShutdown() throws Exception { info(">>> First task executed successfully, running batch."); - for (int i = 0; i < 100; i++) + for (int i = 0; i < 10; i++) futs.add(compute.executeAsync(taskName, taskArg)); // Stop client. diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java index 0103622ca270c..d34f42138665b 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java @@ -21,6 +21,7 @@ import org.apache.ignite.client.marshaller.*; import org.apache.ignite.client.marshaller.optimized.*; import org.apache.ignite.internal.processors.rest.client.message.*; +import org.apache.ignite.internal.processors.rest.protocols.tcp.*; import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -88,17 +89,18 @@ final class TestBinaryClient { req.marshallerId(GridClientOptimizedMarshaller.ID); // Write handshake. - sock.getOutputStream().write(GridClientHandshakeRequestWrapper.HANDSHAKE_HEADER); + sock.getOutputStream().write(GridMemcachedMessage.IGNITE_HANDSHAKE_FLAG); sock.getOutputStream().write(req.rawBytes()); - byte[] buf = new byte[1]; + byte[] buf = new byte[2]; // Wait for handshake response. int read = input.read(buf); - assert read == 1 : read; + assert read == 2 : read; - assert buf[0] == GridClientHandshakeResponse.OK.resultCode() : + assert buf[0] == GridMemcachedMessage.IGNITE_HANDSHAKE_RES_FLAG; + assert buf[1] == GridClientHandshakeResponse.OK.resultCode() : "Client handshake failed [code=" + buf[0] + ']'; } catch (IOException e) { diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/TcpRestParserSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/TcpRestParserSelfTest.java index 070441d788b39..2a7263f5c3cdd 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/TcpRestParserSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/TcpRestParserSelfTest.java @@ -56,7 +56,7 @@ public class TcpRestParserSelfTest extends GridCommonAbstractTest { public void testSimplePacketParsing() throws Exception { GridNioSession ses = new MockNioSession(); - GridTcpRestParser parser = new GridTcpRestParser(); + GridTcpRestParser parser = new GridTcpRestParser(false); byte hdr = MEMCACHE_REQ_FLAG; @@ -91,7 +91,7 @@ public void testSimplePacketParsing() throws Exception { public void testIncorrectPackets() throws Exception { final GridNioSession ses = new MockNioSession(); - final GridTcpRestParser parser = new GridTcpRestParser(); + final GridTcpRestParser parser = new GridTcpRestParser(false); final byte[] opaque = new byte[] {0x01, 0x02, 0x03, (byte)0xFF}; @@ -151,7 +151,7 @@ public void testCustomMessages() throws Exception { ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - GridTcpRestParser parser = new GridTcpRestParser(); + GridTcpRestParser parser = new GridTcpRestParser(false); GridClientMessage msg = parser.decode(ses, raw); @@ -180,7 +180,7 @@ public void testMixedParsing() throws Exception { ses1.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); ses2.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - GridTcpRestParser parser = new GridTcpRestParser(); + GridTcpRestParser parser = new GridTcpRestParser(false); GridClientCacheRequest req = new GridClientCacheRequest(CAS); @@ -266,7 +266,7 @@ public void testParseContinuousSplit() throws Exception { ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - GridTcpRestParser parser = new GridTcpRestParser(); + GridTcpRestParser parser = new GridTcpRestParser(false); Collection lst = new ArrayList<>(5); @@ -308,7 +308,7 @@ public void testParseClientHandshake() throws Exception { ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); - GridTcpRestParser parser = new GridTcpRestParser(); + GridTcpRestParser parser = new GridTcpRestParser(false); Collection lst = new ArrayList<>(1); diff --git a/modules/clients/src/test/resources/spring-cache.xml b/modules/clients/src/test/resources/spring-cache.xml index 4f980be33e29b..4df7806d50707 100644 --- a/modules/clients/src/test/resources/spring-cache.xml +++ b/modules/clients/src/test/resources/spring-cache.xml @@ -229,11 +229,11 @@ - + - - + + diff --git a/modules/clients/src/test/resources/spring-server-node.xml b/modules/clients/src/test/resources/spring-server-node.xml index a36f8662bf0da..992bc74606a5e 100644 --- a/modules/clients/src/test/resources/spring-server-node.xml +++ b/modules/clients/src/test/resources/spring-server-node.xml @@ -73,19 +73,19 @@ - + - - + + - + - + - + diff --git a/modules/clients/src/test/resources/spring-server-ssl-node.xml b/modules/clients/src/test/resources/spring-server-ssl-node.xml index 09891546d26ab..3db6f48b24293 100644 --- a/modules/clients/src/test/resources/spring-server-ssl-node.xml +++ b/modules/clients/src/test/resources/spring-server-ssl-node.xml @@ -293,11 +293,11 @@ - + - - + + diff --git a/modules/codegen/pom.xml b/modules/codegen/pom.xml new file mode 100644 index 0000000000000..5b9e1dba709c5 --- /dev/null +++ b/modules/codegen/pom.xml @@ -0,0 +1,50 @@ + + + + + + + 4.0.0 + + + org.apache.ignite + ignite + ${ignite.version} + ../.. + + + ignite-codegen + + + UTF-8 + 1.7 + 1.7 + + + + + org.apache.ignite + ignite-core + ${ignite.version} + + + 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 new file mode 100644 index 0000000000000..f4c8d94ba21e6 --- /dev/null +++ b/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java @@ -0,0 +1,782 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.codegen; + +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; +import org.jetbrains.annotations.*; + +import java.io.*; +import java.lang.reflect.*; +import java.net.*; +import java.util.*; + +import static java.lang.reflect.Modifier.*; + +/** +* Direct marshallable code generator. +*/ +public class CommunicationMessageCodeGenerator { + /** */ + private static final Comparator FIELD_CMP = new Comparator() { + @Override public int compare(Field f1, Field f2) { + return f1.getName().compareTo(f2.getName()); + } + }; + + /** */ + private static final String[] EXCLUDED_PACKAGES = new String[] { + "org.apache.ignite.internal.processors.rest.client.message", + "org.apache.ignite.internal.processors.rest.protocols.tcp" + }; + + /** */ + private static final String SRC_DIR = U.getIgniteHome() + "/modules/core/src/main/java"; + + /** */ + private static final Class BASE_CLS = MessageAdapter.class; + + /** */ + private static final String EMPTY = ""; + + /** */ + private static final String TAB = " "; + + /** */ + private static final String BUF_VAR = "buf"; + + /** */ + private static final String STATE_VAR = "state"; + + /** */ + private static final String TYPE_WRITTEN_VAR = "typeWritten"; + + /** */ + private final Collection write = new ArrayList<>(); + + /** */ + private final Collection read = new ArrayList<>(); + + /** */ + private final Collection clone = new ArrayList<>(); + + /** */ + private final Collection clone0 = new ArrayList<>(); + + /** */ + private final Map, Integer> fieldCnt = new HashMap<>(); + + /** */ + private List fields; + + /** */ + private int indent; + + /** + * @param args Arguments. + */ + public static void main(String[] args) { + CommunicationMessageCodeGenerator gen = new CommunicationMessageCodeGenerator(); + + try { + gen.generateAll(true); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Generates code for all classes. + * + * @param write Whether to write to file. + * @throws Exception In case of error. + */ + public void generateAll(boolean write) throws Exception { + Collection> classes = classes(); + + for (Class cls : classes) { + boolean isAbstract = Modifier.isAbstract(cls.getModifiers()); + + System.out.println("Processing class: " + cls.getName() + (isAbstract ? " (abstract)" : "")); + + if (write) + generateAndWrite(cls); + else + generate(cls); + } + } + + /** + * Generates code for provided class and writes it to source file. + * Note: this method must be called only from {@code generateAll(boolean)} + * and only with updating {@code CLASSES_ORDER_FILE} and other auto generated files. + * + * @param cls Class. + * @throws Exception In case of error. + */ + @SuppressWarnings("ConstantConditions") + private void generateAndWrite(Class cls) throws Exception { + assert cls != null; + + generate(cls); + + File file = new File(SRC_DIR, cls.getName().replace('.', File.separatorChar) + ".java"); + + if (!file.exists() || !file.isFile()) { + System.out.println(" Source file not found: " + file.getPath()); + + return; + } + + Collection src = new ArrayList<>(); + + BufferedReader rdr = null; + + try { + rdr = new BufferedReader(new FileReader(file)); + + String line; + boolean skip = false; + + boolean writeFound = false; + boolean readFound = false; + boolean cloneFound = false; + boolean clone0Found = false; + + while ((line = rdr.readLine()) != null) { + if (!skip) { + src.add(line); + + if (line.contains("public boolean writeTo(ByteBuffer buf)")) { + src.addAll(write); + + skip = true; + + writeFound = true; + } + else if (line.contains("public boolean readFrom(ByteBuffer buf)")) { + src.addAll(read); + + skip = true; + + readFound = true; + } + else if (line.contains("public MessageAdapter clone()")) { + src.addAll(clone); + + skip = true; + + cloneFound = true; + } + else if (line.contains("protected void clone0(MessageAdapter _msg)")) { + src.addAll(clone0); + + skip = true; + + clone0Found = true; + } + } + else if (line.startsWith(TAB + "}")) { + src.add(line); + + skip = false; + } + } + + if (!writeFound) + System.out.println(" writeTo method doesn't exist."); + + if (!readFound) + System.out.println(" readFrom method doesn't exist."); + + if (!cloneFound) + System.out.println(" clone method doesn't exist."); + + if (!clone0Found) + System.out.println(" clone0 method doesn't exist."); + } + finally { + if (rdr != null) + rdr.close(); + } + + BufferedWriter wr = null; + + try { + wr = new BufferedWriter(new FileWriter(file)); + + for (String line : src) + wr.write(line + '\n'); + } + finally { + if (wr != null) + wr.close(); + } + } + + /** + * Generates code for provided class. + * + * @param cls Class. + * @throws Exception In case of error. + */ + public void generate(Class cls) throws Exception { + assert cls != null; + + write.clear(); + read.clear(); + clone.clear(); + clone0.clear(); + + fields = new ArrayList<>(); + + Field[] declaredFields = cls.getDeclaredFields(); + + for (Field field : declaredFields) { + int mod = field.getModifiers(); + + if (!isStatic(mod) && !isTransient(mod) && !field.isAnnotationPresent(GridDirectTransient.class)) + fields.add(field); + } + + Collections.sort(fields, FIELD_CMP); + + indent = 2; + + boolean hasSuper = cls.getSuperclass() != BASE_CLS; + + 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()); + } + + if (hasSuper) { + clone0.add(builder().a("super.clone0(_msg);").toString()); + clone0.add(EMPTY); + } + + Collection cloningFields = new ArrayList<>(declaredFields.length); + + for (Field field: declaredFields) + if (!isStatic(field.getModifiers())) + cloningFields.add(field); + + if (!cloningFields.isEmpty()) { + clone0.add(builder().a(clsName).a(" _clone = (").a(clsName).a(")_msg;").toString()); + clone0.add(EMPTY); + + for (Field field : cloningFields) { + String name = field.getName(); + Class type = field.getType(); + + String res = name; + + if (BASE_CLS.isAssignableFrom(type)) + res = name + " != null ? (" + type.getSimpleName() + ")" + name + ".clone() : null"; + + clone0.add(builder().a("_clone.").a(name).a(" = ").a(res).a(";").toString()); + } + } + + start(write, hasSuper ? "writeTo" : null, true); + start(read, hasSuper ? "readFrom" : null, false); + + indent++; + + int state = startState(cls); + + for (Field field : fields) + processField(field, state++); + + indent--; + + finish(write); + finish(read); + } + + /** + * @param cls Message class. + * @return Start state. + */ + private int startState(Class cls) { + assert cls != null; + + Class superCls = cls.getSuperclass(); + + Integer state = fieldCnt.get(superCls); + + if (state != null) + return state; + + state = 0; + + while (cls.getSuperclass() != BASE_CLS) { + cls = cls.getSuperclass(); + + for (Field field : cls.getDeclaredFields()) { + int mod = field.getModifiers(); + + if (!isStatic(mod) && !isTransient(mod) && !field.isAnnotationPresent(GridDirectTransient.class)) + state++; + } + } + + fieldCnt.put(superCls, state); + + return state; + } + + /** + * @param code Code lines. + * @param superMtd Super class method name. + * @param write Whether write code is generated. + */ + private void start(Collection code, @Nullable String superMtd, boolean write) { + assert code != null; + + code.add(builder().a(write ? "writer" : "reader").a(".setBuffer(").a(BUF_VAR).a(");").toString()); + code.add(EMPTY); + + if (superMtd != null) { + returnFalseIfFailed(code, "super." + superMtd, BUF_VAR); + + code.add(EMPTY); + } + + if (write) { + code.add(builder().a("if (!").a(TYPE_WRITTEN_VAR).a(") {").toString()); + + indent++; + + returnFalseIfFailed(code, "writer.writeByte", "null", "directType()"); + + code.add(EMPTY); + code.add(builder().a(TYPE_WRITTEN_VAR).a(" = true;").toString()); + + indent--; + + code.add(builder().a("}").toString()); + code.add(EMPTY); + } + + if (!fields.isEmpty()) + code.add(builder().a("switch (").a(STATE_VAR).a(") {").toString()); + } + + /** + * @param code Code lines. + */ + private void finish(Collection code) { + assert code != null; + + if (!fields.isEmpty()) { + code.add(builder().a("}").toString()); + code.add(EMPTY); + } + + code.add(builder().a("return true;").toString()); + } + + /** + * @param field Field. + * @param opt Case option. + */ + private void processField(Field field, int opt) { + assert field != null; + assert opt >= 0; + + GridDirectCollection colAnn = field.getAnnotation(GridDirectCollection.class); + GridDirectMap mapAnn = field.getAnnotation(GridDirectMap.class); + + if (colAnn == null && Collection.class.isAssignableFrom(field.getType())) + throw new IllegalStateException("@GridDirectCollection annotation is not provided for field: " + + field.getName()); + + if (mapAnn == null && Map.class.isAssignableFrom(field.getType())) + throw new IllegalStateException("@GridDirectMap annotation is not provided for field: " + field.getName()); + + writeField(field, opt, colAnn, mapAnn); + readField(field, opt, colAnn, mapAnn); + } + + /** + * @param field Field. + * @param opt Case option. + * @param colAnn Collection annotation. + * @param mapAnn Map annotation. + */ + private void writeField(Field field, int opt, @Nullable GridDirectCollection colAnn, + @Nullable GridDirectMap mapAnn) { + assert field != null; + assert opt >= 0; + + write.add(builder().a("case ").a(opt).a(":").toString()); + + indent++; + + returnFalseIfWriteFailed(field.getType(), field.getName(), colAnn != null ? colAnn.value() : null, + mapAnn != null ? mapAnn.keyType() : null, mapAnn != null ? mapAnn.valueType() : null, false); + + write.add(EMPTY); + write.add(builder().a(STATE_VAR).a("++;").toString()); + write.add(EMPTY); + + indent--; + } + + /** + * @param field Field. + * @param opt Case option. + * @param colAnn Collection annotation. + * @param mapAnn Map annotation. + */ + private void readField(Field field, int opt, @Nullable GridDirectCollection colAnn, + @Nullable GridDirectMap mapAnn) { + assert field != null; + assert opt >= 0; + + read.add(builder().a("case ").a(opt).a(":").toString()); + + indent++; + + returnFalseIfReadFailed(field.getType(), field.getName(), colAnn != null ? colAnn.value() : null, + mapAnn != null ? mapAnn.keyType() : null, mapAnn != null ? mapAnn.valueType() : null); + + read.add(EMPTY); + read.add(builder().a(STATE_VAR).a("++;").toString()); + read.add(EMPTY); + + indent--; + } + + /** + * @param type Field type. + * @param name Field name. + * @param colItemType Collection item type. + * @param mapKeyType Map key type. + * @param mapValType Map key value. + * @param raw Raw write flag. + */ + private void returnFalseIfWriteFailed(Class type, String name, @Nullable Class colItemType, + @Nullable Class mapKeyType, @Nullable Class mapValType, boolean raw) { + assert type != null; + assert name != null; + + String field = raw ? "null" : '"' + name + '"'; + + if (type == byte.class) + returnFalseIfFailed(write, "writer.writeByte", field, name); + else if (type == short.class) + returnFalseIfFailed(write, "writer.writeShort", field, name); + else if (type == int.class) + returnFalseIfFailed(write, "writer.writeInt", field, name); + else if (type == long.class) + returnFalseIfFailed(write, "writer.writeLong", field, name); + else if (type == float.class) + returnFalseIfFailed(write, "writer.writeFloat", field, name); + else if (type == double.class) + returnFalseIfFailed(write, "writer.writeDouble", field, name); + else if (type == char.class) + returnFalseIfFailed(write, "writer.writeChar", field, name); + else if (type == boolean.class) + returnFalseIfFailed(write, "writer.writeBoolean", field, name); + else if (type == byte[].class) + returnFalseIfFailed(write, "writer.writeByteArray", field, name); + else if (type == short[].class) + returnFalseIfFailed(write, "writer.writeShortArray", field, name); + else if (type == int[].class) + returnFalseIfFailed(write, "writer.writeIntArray", field, name); + else if (type == long[].class) + returnFalseIfFailed(write, "writer.writeLongArray", field, name); + else if (type == float[].class) + returnFalseIfFailed(write, "writer.writeFloatArray", field, name); + else if (type == double[].class) + returnFalseIfFailed(write, "writer.writeDoubleArray", field, name); + else if (type == char[].class) + returnFalseIfFailed(write, "writer.writeCharArray", field, name); + else if (type == boolean[].class) + returnFalseIfFailed(write, "writer.writeBooleanArray", field, name); + else if (type == String.class) + returnFalseIfFailed(write, "writer.writeString", field, name); + else if (type == BitSet.class) + returnFalseIfFailed(write, "writer.writeBitSet", field, name); + else if (type == UUID.class) + returnFalseIfFailed(write, "writer.writeUuid", field, name); + else if (type == IgniteUuid.class) + returnFalseIfFailed(write, "writer.writeIgniteUuid", field, name); + else if (type.isEnum()) + returnFalseIfFailed(write, "writer.writeEnum", field, name); + else if (BASE_CLS.isAssignableFrom(type)) + returnFalseIfFailed(write, "writer.writeMessage", field, name); + else if (type.isArray()) { + returnFalseIfFailed(write, "writer.writeObjectArray", field, name, + type.getComponentType().getSimpleName() + ".class"); + } + else if (Collection.class.isAssignableFrom(type) && !Set.class.isAssignableFrom(type)) { + assert colItemType != null; + + returnFalseIfFailed(write, "writer.writeCollection", field, name, colItemType.getSimpleName() + ".class"); + } + else if (Map.class.isAssignableFrom(type)) { + assert mapKeyType != null; + assert mapValType != null; + + returnFalseIfFailed(write, "writer.writeMap", field, name, mapKeyType.getSimpleName() + ".class", + mapValType.getSimpleName() + ".class"); + } + else + throw new IllegalStateException("Unsupported type: " + type); + } + + /** + * @param type Field type. + * @param name Field name. + * @param colItemType Collection item type. + * @param mapKeyType Map key type. + * @param mapValType Map value type. + */ + private void returnFalseIfReadFailed(Class type, @Nullable String name, @Nullable Class colItemType, + @Nullable Class mapKeyType, @Nullable Class mapValType) { + assert type != null; + + String field = '"' + name + '"'; + + if (type == byte.class) + returnFalseIfReadFailed(name, "reader.readByte", field); + else if (type == short.class) + returnFalseIfReadFailed(name, "reader.readShort", field); + else if (type == int.class) + returnFalseIfReadFailed(name, "reader.readInt", field); + else if (type == long.class) + returnFalseIfReadFailed(name, "reader.readLong", field); + else if (type == float.class) + returnFalseIfReadFailed(name, "reader.readFloat", field); + else if (type == double.class) + returnFalseIfReadFailed(name, "reader.readDouble", field); + else if (type == char.class) + returnFalseIfReadFailed(name, "reader.readChar", field); + else if (type == boolean.class) + returnFalseIfReadFailed(name, "reader.readBoolean", field); + else if (type == byte[].class) + returnFalseIfReadFailed(name, "reader.readByteArray", field); + else if (type == short[].class) + returnFalseIfReadFailed(name, "reader.readShortArray", field); + else if (type == int[].class) + returnFalseIfReadFailed(name, "reader.readIntArray", field); + else if (type == long[].class) + returnFalseIfReadFailed(name, "reader.readLongArray", field); + else if (type == float[].class) + returnFalseIfReadFailed(name, "reader.readFloatArray", field); + else if (type == double[].class) + returnFalseIfReadFailed(name, "reader.readDoubleArray", field); + else if (type == char[].class) + returnFalseIfReadFailed(name, "reader.readCharArray", field); + else if (type == boolean[].class) + returnFalseIfReadFailed(name, "reader.readBooleanArray", field); + else if (type == String.class) + returnFalseIfReadFailed(name, "reader.readString", field); + else if (type == BitSet.class) + returnFalseIfReadFailed(name, "reader.readBitSet", field); + else if (type == UUID.class) + returnFalseIfReadFailed(name, "reader.readUuid", field); + else if (type == IgniteUuid.class) + returnFalseIfReadFailed(name, "reader.readIgniteUuid", field); + else if (type.isEnum()) + returnFalseIfReadFailed(name, "reader.readEnum", field, type.getSimpleName() + ".class"); + else if (BASE_CLS.isAssignableFrom(type)) + returnFalseIfReadFailed(name, "reader.readMessage", field); + else if (type.isArray()) { + returnFalseIfReadFailed(name, "reader.readObjectArray", field, + type.getComponentType().getSimpleName() + ".class"); + } + else if (Collection.class.isAssignableFrom(type) && !Set.class.isAssignableFrom(type)) { + assert colItemType != null; + + returnFalseIfReadFailed(name, "reader.readCollection", field, + colItemType.getSimpleName() + ".class"); + } + else if (Map.class.isAssignableFrom(type)) { + assert mapKeyType != null; + assert mapValType != null; + + boolean linked = type.equals(LinkedHashMap.class); + + returnFalseIfReadFailed(name, "reader.readMap", field, mapKeyType.getSimpleName() + ".class", + mapValType.getSimpleName() + ".class", linked ? "true" : "false"); + } + else + throw new IllegalStateException("Unsupported type: " + type); + } + + /** + * @param var Variable name. + * @param mtd Method name. + * @param args Method arguments. + */ + private void returnFalseIfReadFailed(String var, String mtd, @Nullable String... args) { + assert mtd != null; + + String argsStr = ""; + + if (args != null && args.length > 0) { + for (String arg : args) + argsStr += arg + ", "; + + argsStr = argsStr.substring(0, argsStr.length() - 2); + } + + read.add(builder().a(var).a(" = ").a(mtd).a("(").a(argsStr).a(");").toString()); + read.add(EMPTY); + + read.add(builder().a("if (!reader.isLastRead())").toString()); + + indent++; + + read.add(builder().a("return false;").toString()); + + indent--; + } + + /** + * @param code Code lines. + * @param accessor Field or method name. + * @param args Method arguments. + */ + private void returnFalseIfFailed(Collection code, String accessor, @Nullable String... args) { + assert code != null; + assert accessor != null; + + String argsStr = ""; + + if (args != null && args.length > 0) { + for (String arg : args) + argsStr += arg + ", "; + + argsStr = argsStr.substring(0, argsStr.length() - 2); + } + + code.add(builder().a("if (!").a(accessor).a("(").a(argsStr).a("))").toString()); + + indent++; + + code.add(builder().a("return false;").toString()); + + indent--; + } + + /** + * Creates new builder with correct indent. + * + * @return Builder. + */ + private SB builder() { + assert indent > 0; + + SB sb = new SB(); + + for (int i = 0; i < indent; i++) + sb.a(TAB); + + return sb; + } + + /** + * Gets all direct marshallable classes. + * First classes will be classes from {@code classesOrder} with same order + * as ordered values. Other classes will be at the end and ordered by name + * (with package prefix). + * That orders need for saving {@code directType} value. + * + * @return Classes. + * @throws Exception In case of error. + */ + private Collection> classes() throws Exception { + Collection> col = new TreeSet<>( + new Comparator>() { + @Override public int compare(Class c1, + Class c2) { + return c1.getName().compareTo(c2.getName()); + } + }); + + URLClassLoader ldr = (URLClassLoader)getClass().getClassLoader(); + + for (URL url : ldr.getURLs()) { + File file = new File(url.toURI()); + + int prefixLen = file.getPath().length() + 1; + + processFile(file, ldr, prefixLen, col); + } + + return col; + } + + /** + * Recursively process provided file or directory. + * + * @param file File. + * @param ldr Class loader. + * @param prefixLen Path prefix length. + * @param col Classes. + * @throws Exception In case of error. + */ + private void processFile(File file, ClassLoader ldr, int prefixLen, + Collection> col) throws Exception { + assert file != null; + assert ldr != null; + assert prefixLen > 0; + assert col != null; + + if (!file.exists()) + throw new FileNotFoundException("File doesn't exist: " + file); + + if (file.isDirectory()) { + for (File f : file.listFiles()) + processFile(f, ldr, prefixLen, col); + } + else { + assert file.isFile(); + + String path = file.getPath(); + + if (path.endsWith(".class")) { + String clsName = path.substring(prefixLen, path.length() - 6).replace(File.separatorChar, '.'); + + for (String excluded : EXCLUDED_PACKAGES) { + if (clsName.startsWith(excluded)) + return; + } + + Class cls = Class.forName(clsName, false, ldr); + + if (cls.getDeclaringClass() == null && cls.getEnclosingClass() == null && + !BASE_CLS.equals(cls) && BASE_CLS.isAssignableFrom(cls)) + col.add((Class)cls); + } + } + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java index d6c038d232ca1..d8c0f61891452 100644 --- a/modules/core/src/main/java/org/apache/ignite/Ignite.java +++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java @@ -197,13 +197,6 @@ public interface Ignite extends AutoCloseable { */ public GridSecurity security(); - /** - * Gets an instance of {@code GridPortables} interface. Available in enterprise edition only. - * - * @return Instance of {@code GridPortables} interface. - */ - public IgnitePortables portables(); - /** * Gets the cache instance for the given name, if one does not * exist {@link IllegalArgumentException} will be thrown. diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java index f100464c0e8fd..4d5ecc39d5460 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java @@ -293,7 +293,7 @@ public interface IgniteCache extends javax.cache.Cache, IgniteAsyncS * so keys and values will be returned from cache API methods without changes. Therefore, * signature of the projection can contain only following types: *
    - *
  • {@link org.apache.ignite.portables.PortableObject} for portable classes
  • + *
  • {@link org.gridgain.grid.portables.PortableObject} for portable classes
  • *
  • All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
  • *
  • Arrays of primitives (byte[], int[], ...)
  • *
  • {@link String} and array of {@link String}s
  • diff --git a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java b/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java deleted file mode 100644 index 68579616ff43e..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite; - -import org.apache.ignite.portables.*; -import org.jetbrains.annotations.*; - -import java.sql.*; -import java.util.*; -import java.util.Date; - -/** - * Defines portable objects functionality. With portable objects you are able to: - *
      - *
    • Seamlessly interoperate between Java, .NET, and C++.
    • - *
    • Make any object portable with zero code change to your existing code.
    • - *
    • Nest portable objects within each other.
    • - *
    • Automatically handle {@code circular} or {@code null} references.
    • - *
    • Automatically convert collections and maps between Java, .NET, and C++.
    • - *
    • - * Optionally avoid deserialization of objects on the server side - * (objects are stored in {@link org.apache.ignite.portables.PortableObject} format). - *
    • - *
    • Avoid need to have concrete class definitions on the server side.
    • - *
    • Dynamically change structure of the classes without having to restart the cluster.
    • - *
    • Index into portable objects for querying purposes.
    • - *
    - *

    Working With Portables Directly

    - * Once an object is defined as portable, - * Ignite will always store it in memory in the portable (i.e. binary) format. - * User can choose to work either with the portable format or with the deserialized form - * (assuming that class definitions are present in the classpath). - *

    - * To work with the portable format directly, user should create a special cache projection - * using {@link org.apache.ignite.cache.CacheProjection#keepPortable()} method and then retrieve individual fields as needed: - *

    - * CacheProjection<GridPortableObject.class, GridPortableObject.class> prj = cache.keepPortable();
    - *
    - * // Convert instance of MyKey to portable format.
    - * // We could also use GridPortableBuilder to create
    - * // the key in portable format directly.
    - * GridPortableObject key = grid.portables().toPortable(new MyKey());
    - *
    - * GridPortableObject val = prj.get(key);
    - *
    - * String field = val.field("myFieldName");
    - * 
    - * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized - * typed objects at all times. In this case we do incur the deserialization cost, however, - * Ignite will only deserialize on the first access and will cache the deserialized object, - * so it does not have to be deserialized again: - *
    - * CacheProjection<MyKey.class, MyValue.class> prj =
    - *     cache.projection(MyKey.class, MyValue.class);
    - *
    - * MyValue val = prj.get(new MyKey());
    - *
    - * // Normal java getter.
    - * String fieldVal = val.getMyFieldName();
    - * 
    - * If we used, for example, one of the automatically handled portable types for a key, like integer, - * and still wanted to work with binary portable format for values, then we would declare cache projection - * as follows: - *
    - * CacheProjection<Integer.class, GridPortableObject.class> prj = cache.keepPortable();
    - * 
    - *

    Automatic Portable Types

    - * Note that only portable classes are converted to {@link org.apache.ignite.portables.PortableObject} format. Following - * classes are never converted (e.g., {@link #toPortable(Object)} method will return original - * object, and instances of these classes will be stored in cache without changes): - *
      - *
    • All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
    • - *
    • Arrays of primitives (byte[], int[], ...)
    • - *
    • {@link String} and array of {@link String}s
    • - *
    • {@link UUID} and array of {@link UUID}s
    • - *
    • {@link Date} and array of {@link Date}s
    • - *
    • {@link Timestamp} and array of {@link Timestamp}s
    • - *
    • Enums and array of enums
    • - *
    • - * Maps, collections and array of objects (but objects inside - * them will still be converted if they are portable) - *
    • - *
    - *

    Working With Maps and Collections

    - * All maps and collections in the portable objects are serialized automatically. When working - * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most - * adequate collection or map in either language. For example, {@link ArrayList} in Java will become - * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap} - * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary} - * in C#, etc. - *

    Building Portable Objects

    - * Ignite comes with {@link org.apache.ignite.portables.PortableBuilder} which allows to build portable objects dynamically: - *
    - * GridPortableBuilder builder = Ignition.ignite().portables().builder();
    - *
    - * builder.typeId("MyObject");
    - *
    - * builder.stringField("fieldA", "A");
    - * build.intField("fieldB", "B");
    - *
    - * GridPortableObject portableObj = builder.build();
    - * 
    - * For the cases when class definition is present - * in the class path, it is also possible to populate a standard POJO and then - * convert it to portable format, like so: - *
    - * MyObject obj = new MyObject();
    - *
    - * obj.setFieldA("A");
    - * obj.setFieldB(123);
    - *
    - * GridPortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
    - * 
    - * NOTE: you don't need to convert typed objects to portable format before storing - * them in cache, Ignite will do that automatically. - *

    Portable Metadata

    - * Even though Ignite portable protocol only works with hash codes for type and field names - * to achieve better performance, Ignite provides metadata for all portable types which - * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class) GridPortables.metadata(...)} - * methods. Having metadata also allows for proper formatting of {@code GridPortableObject.toString()} method, - * even when portable objects are kept in binary format only, which may be necessary for audit reasons. - *

    Dynamic Structure Changes

    - * Since objects are always cached in the portable binary format, server does not need to - * be aware of the class definitions. Moreover, if class definitions are not present or not - * used on the server, then clients can continuously change the structure of the portable - * objects without having to restart the cluster. For example, if one client stores a - * certain class with fields A and B, and another client stores the same class with - * fields B and C, then the server-side portable object will have the fields A, B, and C. - * As the structure of a portable object changes, the new fields become available for SQL queries - * automatically. - *

    Configuration

    - * To make any object portable, you have to specify it in {@link org.apache.ignite.portables.PortableConfiguration} - * at startup. The only requirement Ignite imposes is that your object has an empty - * constructor. Note, that since server side does not have to know the class definition, - * you only need to list portable objects in configuration on the client side. However, if you - * list them on the server side as well, then you get the ability to deserialize portable objects - * into concrete types on the server as well as on the client. - *

    - * Here is an example of portable configuration (note that star (*) notation is supported): - *

    - * ...
    - * <!-- Portable objects configuration. -->
    - * <property name="portableConfiguration">
    - *     <bean class="org.apache.ignite.portables.PortableConfiguration">
    - *         <property name="classNames">
    - *             <list>
    - *                 <value>my.package.for.portable.objects.*</value>
    - *                 <value>org.apache.ignite.examples.client.portable.Employee</value>
    - *             </list>
    - *         </property>
    - *     </bean>
    - * </property>
    - * ...
    - * 
    - * or from code: - *
    - * GridConfiguration gridCfg = new GridConfiguration();
    - *
    - * GridPortableConfiguration portCfg = new GridPortableConfiguration();
    - *
    - * portCfg.setClassNames(Arrays.asList(
    - *     Employee.class.getName(),
    - *     Address.class.getName())
    - * );
    - *
    - * gridCfg.setPortableConfiguration(portCfg);
    - * 
    - * You can also specify class name for a portable object via {@link org.apache.ignite.portables.PortableTypeConfiguration}. - * Do it in case if you need to override other configuration properties on per-type level, like - * ID-mapper, or serializer. - *

    Custom Affinity Keys

    - * Often you need to specify an alternate key (not the cache key) for affinity routing whenever - * storing objects in cache. For example, if you are caching {@code Employee} object with - * {@code Organization}, and want to colocate employees with organization they work for, - * so you can process them together, you need to specify an alternate affinity key. - * With portable objects you would have to do it as following: - *
    - * <property name="portableConfiguration">
    - *     <bean class="org.apache.ignite.portables.PortableConfiguration">
    - *         ...
    - *         <property name="typeConfigurations">
    - *             <list>
    - *                 <bean class="org.apache.ignite.portables.PortableTypeConfiguration">
    - *                     <property name="className" value="org.apache.ignite.examples.client.portable.EmployeeKey"/>
    - *                     <property name="affinityKeyFieldName" value="organizationId"/>
    - *                 </bean>
    - *             </list>
    - *         </property>
    - *         ...
    - *     </bean>
    - * </property>
    - * 
    - *

    Serialization

    - * Once portable object is specified in {@link org.apache.ignite.portables.PortableConfiguration}, Ignite will - * be able to serialize and deserialize it. However, you can provide your own custom - * serialization logic by optionally implementing {@link org.apache.ignite.portables.PortableMarshalAware} interface, like so: - *
    - * public class Address implements GridPortableMarshalAware {
    - *     private String street;
    - *     private int zip;
    - *
    - *     // Empty constructor required for portable deserialization.
    - *     public Address() {}
    - *
    - *     @Override public void writePortable(GridPortableWriter writer) throws GridPortableException {
    - *         writer.writeString("street", street);
    - *         writer.writeInt("zip", zip);
    - *     }
    - *
    - *     @Override public void readPortable(GridPortableReader reader) throws GridPortableException {
    - *         street = reader.readString("street");
    - *         zip = reader.readInt("zip");
    - *     }
    - * }
    - * 
    - * Alternatively, if you cannot change class definitions, you can provide custom serialization - * logic in {@link org.apache.ignite.portables.PortableSerializer} either globally in {@link org.apache.ignite.portables.PortableConfiguration} or - * for a specific type via {@link org.apache.ignite.portables.PortableTypeConfiguration} instance. - *

    - * Similar to java serialization you can use {@code writeReplace()} and {@code readResolve()} methods. - *

      - *
    • - * {@code readResolve} is defined as follows: {@code ANY-ACCESS-MODIFIER Object readResolve()}. - * It may be used to replace the de-serialized object by another one of your choice. - *
    • - *
    • - * {@code writeReplace} is defined as follows: {@code ANY-ACCESS-MODIFIER Object writeReplace()}. This method allows the - * developer to provide a replacement object that will be serialized instead of the original one. - *
    • - *
    - * - *

    Custom ID Mappers

    - * Ignite implementation uses name hash codes to generate IDs for class names or field names - * internally. However, in cases when you want to provide your own ID mapping schema, - * you can provide your own {@link org.apache.ignite.portables.PortableIdMapper} implementation. - *

    - * ID-mapper may be provided either globally in {@link org.apache.ignite.portables.PortableConfiguration}, - * or for a specific type via {@link org.apache.ignite.portables.PortableTypeConfiguration} instance. - *

    Query Indexing

    - * Portable objects can be indexed for querying by specifying index fields in - * {@link org.apache.ignite.cache.CacheTypeMetadata} inside of specific {@link org.apache.ignite.configuration.CacheConfiguration} instance, - * like so: - *
    - * ...
    - * <bean class="org.apache.ignite.cache.CacheConfiguration">
    - *     ...
    - *     <property name="queryConfiguration">
    - *         <bean class="CacheQueryConfiguration">
    - *             <property name="typeMetadata">
    - *                 <list>
    - *                     <bean class="CacheTypeMetadata">
    - *                         <property name="type" value="Employee"/>
    - *
    - *                         <!-- Fields to index in ascending order. -->
    - *                         <property name="ascendingFields">
    - *                             <map>
    - *                             	<entry key="name" value="java.lang.String"/>
    - *
    - *                                 <!-- Nested portable objects can also be indexed. -->
    - *                                 <entry key="address.zip" value="java.lang.Integer"/>
    - *                             </map>
    - *                         </property>
    - *                     </bean>
    - *                 </list>
    - *             </property>
    - *         </bean>
    - *     </property>
    - * </bean>
    - * 
    - */ -public interface IgnitePortables { - /** - * Gets type ID for given type name. - * - * @param typeName Type name. - * @return Type ID. - */ - public int typeId(String typeName); - - /** - * Converts provided object to instance of {@link org.apache.ignite.portables.PortableObject}. - *

    - * Note that object's type needs to be configured in {@link org.apache.ignite.portables.PortableConfiguration}. - * - * @param obj Object to convert. - * @return Converted object. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - public T toPortable(@Nullable Object obj) throws PortableException; - - /** - * Creates new portable builder. - * - * @param typeId ID of the type. - * @return Newly portable builder. - */ - public PortableBuilder builder(int typeId); - - /** - * Creates new portable builder. - * - * @param typeName Type name. - * @return Newly portable builder. - */ - public PortableBuilder builder(String typeName); - - /** - * Creates portable builder initialized by existing portable object. - * - * @param portableObj Portable object to initialize builder. - * @return Portable builder. - */ - public PortableBuilder builder(PortableObject portableObj); - - /** - * Gets metadata for provided class. - * - * @param cls Class. - * @return Metadata. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - @Nullable public PortableMetadata metadata(Class cls) throws PortableException; - - /** - * Gets metadata for provided class name. - * - * @param typeName Type name. - * @return Metadata. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - @Nullable public PortableMetadata metadata(String typeName) throws PortableException; - - /** - * Gets metadata for provided type ID. - * - * @param typeId Type ID. - * @return Metadata. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - @Nullable public PortableMetadata metadata(int typeId) throws PortableException; - - /** - * Gets metadata for all known types. - * - * @return Metadata. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - public Collection metadata() throws PortableException; -} diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java index fd378d4103b56..b6e4dc1546022 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java @@ -290,7 +290,7 @@ public interface CacheProjection extends Iterable> { * so keys and values will be returned from cache API methods without changes. Therefore, * signature of the projection can contain only following types: *

      - *
    • {@link org.apache.ignite.portables.PortableObject} for portable classes
    • + *
    • {@link org.gridgain.grid.portables.PortableObject} for portable classes
    • *
    • All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
    • *
    • Arrays of primitives (byte[], int[], ...)
    • *
    • {@link String} and array of {@link String}s
    • @@ -477,9 +477,17 @@ public interface CacheProjection extends Iterable> { * @param key Key. * @param peekModes Peek modes. * @return Value. + * @throws IgniteCheckedException If failed. */ @Nullable public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException; + /** + * @param peekModes Peek modes. + * @return Entries iterable. + * @throws IgniteCheckedException If failed. + */ + public Iterable> localEntries(CachePeekMode[] peekModes) throws IgniteCheckedException; + /** * Peeks at cached value using optional set of peek modes. This method will sequentially * iterate over given peek modes in the order passed in, and try to peek at value using @@ -1408,6 +1416,11 @@ public IgniteTx txStartPartition(int partId, IgniteTxConcurrency concurrency, */ public void clear() throws IgniteCheckedException; + /** + * @return Clear future. + */ + public IgniteInternalFuture clearAsync(); + /** * Clears cache on all nodes that store it's data. That is, caches are cleared on remote * nodes and local node, as opposed to {@link CacheProjection#clearLocally()} method which only @@ -1669,6 +1682,11 @@ public IgniteInternalFuture removeAllAsync(@Nullable Collection */ public void removeAll() throws IgniteCheckedException; + /** + * @return Remove future. + */ + public IgniteInternalFuture removeAllAsync(); + /** * Asynchronously removes mappings from cache for entries for which the optionally passed in filters do * pass. If passed in filters are {@code null}, then all entries in cache will be enrolled @@ -1874,6 +1892,26 @@ public void unlockAll(@Nullable Collection keys, */ public int size(); + /** + * @param peekModes Peek modes. + * @return Local cache size. + * @throws IgniteCheckedException If failed. + */ + public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException; + + /** + * @param peekModes Peek modes. + * @return Global cache size. + * @throws IgniteCheckedException If failed. + */ + public int size(CachePeekMode[] peekModes) throws IgniteCheckedException; + + /** + * @param peekModes Peek modes. + * @return Future. + */ + public IgniteInternalFuture sizeAsync(CachePeekMode[] peekModes); + /** * Gets the number of all entries cached across all nodes. *

      diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStore.java index 367773fe6d33e..114b56e77eb66 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStore.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStore.java @@ -20,7 +20,6 @@ import org.apache.ignite.*; import org.apache.ignite.cache.store.jdbc.*; import org.apache.ignite.lang.*; -import org.apache.ignite.portables.*; import org.apache.ignite.resources.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; @@ -69,8 +68,8 @@ * } * *

      Working With Portable Objects

      - * When portables are enabled for cache by setting {@link org.apache.ignite.configuration.CacheConfiguration#isPortableEnabled()} to - * {@code true}), all portable keys and values are converted to instances of {@link PortableObject}. + * When portables are enabled for cache by setting {@code org.apache.ignite.configuration.CacheConfiguration#isPortableEnabled()} to + * {@code true}), all portable keys and values are converted to instances of {@code PortableObject}. * Therefore, all cache store methods will take parameters in portable format. To avoid class * cast exceptions, store must have signature compatible with portables. E.g., if you use {@link Integer} * as a key and {@code Value} class as a value (which will be converted to portable format), cache store @@ -84,7 +83,7 @@ * ... * } * - * This behavior can be overridden by setting {@link org.apache.ignite.configuration.CacheConfiguration#setKeepPortableInStore(boolean)} + * This behavior can be overridden by setting {@code org.apache.ignite.configuration.CacheConfiguration#setKeepPortableInStore(boolean)} * flag value to {@code false}. In this case, Ignite will deserialize keys and values stored in portable * format before they are passed to cache store, so that you can use the following cache store signature instead: *
      @@ -100,7 +99,7 @@
        * due to additional serializations and deserializations of portable objects. You will also need to have key
        * and value classes on all nodes since portables will be deserialized when store is invoked.
        * 

      - * Note that only portable classes are converted to {@link PortableObject} format. Following + * Note that only portable classes are converted to {@code PortableObject} format. Following * types are stored in cache without changes and therefore should not affect cache store signature: *

        *
      • All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
      • @@ -116,7 +115,6 @@ * *
      * - * @see IgnitePortables * @see CacheStoreSession */ public abstract class CacheStore implements CacheLoader, CacheWriter { diff --git a/modules/core/src/main/java/org/apache/ignite/client/GridClientCacheFlag.java b/modules/core/src/main/java/org/apache/ignite/client/GridClientCacheFlag.java index 9cf307ed54d39..eeba6583dc84e 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/GridClientCacheFlag.java +++ b/modules/core/src/main/java/org/apache/ignite/client/GridClientCacheFlag.java @@ -43,7 +43,7 @@ public enum GridClientCacheFlag { * Disable deserialization of portable objects on get operations. * If set and portable marshaller is used, {@link GridClientData#get(Object)} * and {@link GridClientData#getAll(Collection)} methods will return - * instances of {@link org.apache.ignite.portables.PortableObject} class instead of user objects. + * instances of {@link org.gridgain.grid.portables.PortableObject} class instead of user objects. * Use this flag if you don't have corresponding class on your client of * if you want to get access to some individual fields, but do not want to * fully deserialize the object. diff --git a/modules/core/src/main/java/org/apache/ignite/client/GridClientConfiguration.java b/modules/core/src/main/java/org/apache/ignite/client/GridClientConfiguration.java index d571f470a6ea3..bf3a01374dc94 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/GridClientConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/client/GridClientConfiguration.java @@ -25,7 +25,6 @@ import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.plugin.security.*; -import org.apache.ignite.portables.*; import org.jetbrains.annotations.*; import java.net.*; @@ -117,9 +116,6 @@ public class GridClientConfiguration { /** Daemon flag. */ private boolean daemon; - /** Portable configuration. */ - private PortableConfiguration portableCfg; - /** * Creates default configuration. */ @@ -154,7 +150,6 @@ public GridClientConfiguration(GridClientConfiguration cfg) { topRefreshFreq = cfg.getTopologyRefreshFrequency(); daemon = cfg.isDaemon(); marshaller = cfg.getMarshaller(); - portableCfg = cfg.getPortableConfiguration(); setDataConfigurations(cfg.getDataConfigurations()); } @@ -631,24 +626,6 @@ public void setMarshaller(GridClientMarshaller marshaller) { this.marshaller = marshaller; } - /** - * Gets portable configuration. - * - * @return Portable configuration. - */ - public PortableConfiguration getPortableConfiguration() { - return portableCfg; - } - - /** - * Sets portable configuration. - * - * @param portableCfg Portable configuration. - */ - public void setPortableConfiguration(@Nullable PortableConfiguration portableCfg) { - this.portableCfg = portableCfg; - } - /** * Load client configuration from the properties map. * diff --git a/modules/core/src/main/java/org/apache/ignite/client/GridClientFactory.java b/modules/core/src/main/java/org/apache/ignite/client/GridClientFactory.java index 647155e018d8c..339a9f7a97a36 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/GridClientFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/client/GridClientFactory.java @@ -54,7 +54,7 @@ public static GridClient start(GridClientConfiguration cfg) throws GridClientExc try { UUID clientId = UUID.randomUUID(); - GridClientImpl client = new GridClientImpl(clientId, cfg); + GridClientImpl client = new GridClientImpl(clientId, cfg, false); GridClientImpl old = openClients.putIfAbsent(clientId, client); diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/GridClientImpl.java b/modules/core/src/main/java/org/apache/ignite/client/impl/GridClientImpl.java index 8f64a79188228..43b8d2004744c 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/impl/GridClientImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/client/impl/GridClientImpl.java @@ -103,12 +103,13 @@ public class GridClientImpl implements GridClient { * * @param id Client identifier. * @param cfg0 Client configuration. + * @param routerClient Router client flag. * @throws GridClientException If client configuration is incorrect. * @throws GridServerUnreachableException If none of the servers specified in configuration can * be reached. */ @SuppressWarnings("CallToThreadStartDuringObjectConstruction") - public GridClientImpl(UUID id, GridClientConfiguration cfg0) throws GridClientException { + public GridClientImpl(UUID id, GridClientConfiguration cfg0, boolean routerClient) throws GridClientException { this.id = id; cfg = new GridClientConfiguration(cfg0); @@ -158,7 +159,7 @@ public GridClientImpl(UUID id, GridClientConfiguration cfg0) throws GridClientEx throw new GridClientException("Servers addresses and routers addresses cannot both be provided " + "for client (please fix configuration and restart): " + this); - connMgr = createConnectionManager(id, sslCtx, cfg, routers, top, null); + connMgr = createConnectionManager(id, sslCtx, cfg, routers, top, null, routerClient); try { // Init connection manager, it should cause topology update. @@ -385,8 +386,9 @@ private static Collection parseAddresses(Collection c * @return New connection manager based on current client settings. * @throws GridClientException If failed to start connection server. */ - public GridClientConnectionManager newConnectionManager(@Nullable Byte marshId) throws GridClientException { - return createConnectionManager(id, sslCtx, cfg, routers, top, marshId); + public GridClientConnectionManager newConnectionManager(@Nullable Byte marshId, boolean routerClient) + throws GridClientException { + return createConnectionManager(id, sslCtx, cfg, routers, top, marshId, routerClient); } /** @@ -399,7 +401,7 @@ public GridClientConnectionManager newConnectionManager(@Nullable Byte marshId) */ private GridClientConnectionManager createConnectionManager(UUID clientId, SSLContext sslCtx, GridClientConfiguration cfg, Collection routers, GridClientTopology top, - @Nullable Byte marshId) + @Nullable Byte marshId, boolean routerClient) throws GridClientException { GridClientConnectionManager mgr; @@ -409,10 +411,11 @@ private GridClientConnectionManager createConnectionManager(UUID clientId, SSLCo Constructor cons = cls.getConstructor(UUID.class, SSLContext.class, GridClientConfiguration.class, Collection.class, GridClientTopology.class, Byte.class); - mgr = (GridClientConnectionManager)cons.newInstance(clientId, sslCtx, cfg, routers, top, marshId); + mgr = (GridClientConnectionManager)cons.newInstance(clientId, sslCtx, cfg, routers, top, marshId, + routerClient); } catch (ClassNotFoundException ignored) { - mgr = new GridClientConnectionManagerOsImpl(clientId, sslCtx, cfg, routers, top, marshId); + mgr = new GridClientConnectionManagerOsImpl(clientId, sslCtx, cfg, routers, top, marshId, routerClient); } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new GridClientException("Failed to create client connection manager.", e); 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 fbc90879dae22..b689b9b6cfb0c 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 @@ -22,7 +22,7 @@ import org.apache.ignite.client.impl.*; import org.apache.ignite.client.util.*; import org.apache.ignite.internal.processors.rest.client.message.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.internal.processors.rest.protocols.tcp.*; import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.nio.ssl.*; import org.apache.ignite.internal.util.typedef.*; @@ -95,44 +95,6 @@ abstract class GridClientConnectionManagerAdapter implements GridClientConnectio /** Marshaller ID. */ private final Byte marshId; - /** Message writer. */ - @SuppressWarnings("FieldCanBeLocal") - private final GridNioMessageWriter msgWriter = new GridNioMessageWriter() { - @Override public boolean write(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, ByteBuffer buf) { - assert msg != null; - assert buf != null; - - msg.messageWriter(this, nodeId); - - return msg.writeTo(buf); - } - - @Override public int writeFully(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, OutputStream out, - ByteBuffer buf) throws IOException { - assert msg != null; - assert out != null; - assert buf != null; - assert buf.hasArray(); - - msg.messageWriter(this, nodeId); - - boolean finished = false; - int cnt = 0; - - while (!finished) { - finished = msg.writeTo(buf); - - out.write(buf.array(), 0, buf.position()); - - cnt += buf.position(); - - buf.clear(); - } - - return cnt; - } - }; - /** * @param clientId Client ID. * @param sslCtx SSL context to enable secured connection or {@code null} to use unsecured one. @@ -148,7 +110,8 @@ protected GridClientConnectionManagerAdapter(UUID clientId, GridClientConfiguration cfg, Collection routers, GridClientTopology top, - @Nullable Byte marshId) + @Nullable Byte marshId, + boolean routerClient) throws GridClientException { assert clientId != null : "clientId != null"; assert cfg != null : "cfg != null"; @@ -180,28 +143,12 @@ protected GridClientConnectionManagerAdapter(UUID clientId, GridNioFilter[] filters; - GridNioMessageReader msgReader = new GridNioMessageReader() { - @Override public boolean read(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, - ByteBuffer buf) { - assert msg != null; - assert buf != null; - - msg.messageReader(this, nodeId); - - return msg.readFrom(buf); - } - - @Nullable @Override public GridTcpMessageFactory messageFactory() { - return null; - } - }; - - GridNioFilter codecFilter = new GridNioCodecFilter(new NioParser(msgReader), gridLog, true); + GridNioFilter codecFilter = new GridNioCodecFilter(new GridTcpRestParser(routerClient), gridLog, false); if (sslCtx != null) { GridNioSslFilter sslFilter = new GridNioSslFilter(sslCtx, gridLog); - sslFilter.directMode(true); + sslFilter.directMode(false); sslFilter.clientMode(true); filters = new GridNioFilter[]{codecFilter, sslFilter}; @@ -219,12 +166,11 @@ protected GridClientConnectionManagerAdapter(UUID clientId, .byteOrder(ByteOrder.nativeOrder()) .tcpNoDelay(cfg.isTcpNoDelay()) .directBuffer(true) - .directMode(true) + .directMode(false) .socketReceiveBufferSize(0) .socketSendBufferSize(0) .idleTimeout(Long.MAX_VALUE) - .gridName("gridClient") - .messageWriter(msgWriter) + .gridName(routerClient ? "routerClient" : "gridClient") .daemon(cfg.isDaemon()) .build(); @@ -648,21 +594,15 @@ private NioListener(Logger log) { assert conn != null; - if (msg instanceof GridClientMessageWrapper) { - GridClientMessageWrapper req = (GridClientMessageWrapper)msg; - - if (req.messageSize() != 0) { - assert req.message() != null; - - conn.handleResponse(req); - } - else - conn.handlePingResponse(); - } - else { - assert msg instanceof GridClientPingPacket : msg; - + if (msg instanceof GridClientPingPacket) conn.handlePingResponse(); + else { + try { + conn.handleResponse((GridClientMessage)msg); + } + catch (IOException e) { + log.log(Level.SEVERE, "Failed to parse response.", e); + } } } } @@ -701,63 +641,4 @@ private void handleHandshakeResponse(GridClientFutureAdapter handshakeF ses.close(); } } - - /** - * - */ - private static class NioParser implements GridNioParser { - /** Message metadata key. */ - private static final int MSG_META_KEY = GridNioSessionMetaKey.nextUniqueKey(); - - /** Message reader. */ - private final GridNioMessageReader msgReader; - - /** - * @param msgReader Message reader. - */ - NioParser(GridNioMessageReader msgReader) { - this.msgReader = msgReader; - } - - /** {@inheritDoc} */ - @Nullable @Override public Object decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException { - GridClientFutureAdapter handshakeFut = ses.meta(GridClientNioTcpConnection.SES_META_HANDSHAKE); - - if (handshakeFut != null) { - byte code = buf.get(); - - return new GridClientHandshakeResponse(code); - } - - GridTcpCommunicationMessageAdapter msg = ses.removeMeta(MSG_META_KEY); - - if (msg == null && buf.hasRemaining()) { - byte type = buf.get(); - - if (type == GridClientMessageWrapper.REQ_HEADER) - msg = new GridClientMessageWrapper(); - else - throw new IOException("Invalid message type: " + type); - } - - boolean finished = false; - - if (buf.hasRemaining()) - finished = msgReader.read(null, msg, buf); - - if (finished) - return msg; - else { - ses.addMeta(MSG_META_KEY, msg); - - return null; - } - } - - /** {@inheritDoc} */ - @Override public ByteBuffer encode(GridNioSession ses, Object msg) throws IOException, IgniteCheckedException { - // No encoding needed for direct messages. - throw new UnsupportedEncodingException(); - } - } } diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerOsImpl.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerOsImpl.java index f2d4506321585..a9bd80e5c61a2 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerOsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerOsImpl.java @@ -36,8 +36,9 @@ public class GridClientConnectionManagerOsImpl extends GridClientConnectionManag * @throws GridClientException In case of error. */ public GridClientConnectionManagerOsImpl(UUID clientId, SSLContext sslCtx, GridClientConfiguration cfg, - Collection routers, GridClientTopology top, Byte marshId) throws GridClientException { - super(clientId, sslCtx, cfg, routers, top, marshId); + Collection routers, GridClientTopology top, Byte marshId, boolean routerClient) + throws GridClientException { + super(clientId, sslCtx, cfg, routers, top, marshId, routerClient); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java index 51da3d7571015..03fa95d8ba76e 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java +++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java @@ -33,7 +33,6 @@ import javax.net.ssl.*; import java.io.*; import java.net.*; -import java.nio.*; import java.nio.channels.*; import java.util.*; import java.util.concurrent.*; @@ -43,6 +42,7 @@ import static org.apache.ignite.client.GridClientCacheFlag.*; import static org.apache.ignite.client.impl.connection.GridClientConnectionCloseReason.*; import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; +import static org.apache.ignite.internal.util.nio.GridNioSessionMetaKey.*; /** * This class performs request to grid over tcp protocol. Serialization is performed with marshaller @@ -194,9 +194,9 @@ else if (marsh instanceof GridClientOptimizedMarshaller) else if (marsh instanceof GridClientJdkMarshaller) req.marshallerId(GridClientJdkMarshaller.ID); - GridClientHandshakeRequestWrapper wrapper = new GridClientHandshakeRequestWrapper(req); + ses.addMeta(MARSHALLER.ordinal(), marsh); - ses.send(wrapper); + ses.send(req); handshakeFut.get(); @@ -392,7 +392,7 @@ private GridClientFutureAdapter makeRequest(GridClientMessage msg, final else if (now - lastPingSndTime > pingInterval && lastPingRcvTime != Long.MAX_VALUE) { lastPingRcvTime = Long.MAX_VALUE; - ses.send(new GridClientPingPacketWrapper()); + ses.send(GridClientPingPacket.PING_MESSAGE); lastPingSndTime = now; } @@ -415,22 +415,7 @@ else if (now - lastPingSndTime > pingInterval && lastPingRcvTime != Long.MAX_VAL assert old == null; - GridClientMessageWrapper wrapper; - - try { - wrapper = messageWrapper(msg); - } - catch (IOException e) { - log.log(Level.SEVERE, "Failed to marshal message: " + msg, e); - - removePending(reqId); - - fut.onDone(e); - - return fut; - } - - GridNioFuture sndFut = ses.send(wrapper); + GridNioFuture sndFut = ses.send(msg); lastMsgSndTime = U.currentTimeMillis(); @@ -473,59 +458,41 @@ void handlePingResponse() { * Handles incoming response message. If this connection is closed this method would signal empty event * if there is no more pending requests. * - * @param req Incoming response data. + * @param res Incoming response data. */ @SuppressWarnings({"unchecked", "TooBroadScope"}) - void handleResponse(GridClientMessageWrapper req) { + void handleResponse(GridClientMessage res) throws IOException { lastMsgRcvTime = U.currentTimeMillis(); - TcpClientFuture fut = pendingReqs.get(req.requestId()); + TcpClientFuture fut = pendingReqs.get(res.requestId()); if (fut == null) { log.warning("Response for an unknown request is received, ignoring. " + - "[req=" + req + ", ses=" + ses + ']'); + "[res=" + res + ", ses=" + ses + ']'); return; } if (fut.forward()) { - GridRouterResponse msg = new GridRouterResponse( - req.messageArray(), - req.requestId(), - clientId, - req.destinationId()); - - removePending(msg.requestId()); + removePending(res.requestId()); - fut.onDone(msg); + fut.onDone(res); } else { - GridClientMessage msg; + GridClientMessage res0 = res; - if (keepPortablesMode != null) - keepPortablesMode.set(fut.keepPortables()); + if (res instanceof GridRouterResponse) { + res0 = marsh.unmarshal(((GridRouterResponse)res).body()); - try { - msg = marsh.unmarshal(req.messageArray()); + res0.requestId(res.requestId()); + res0.clientId(res.clientId()); + res0.destinationId(res.destinationId()); } - catch (IOException e) { - fut.onDone(new GridClientException("Failed to unmarshal message.", e)); - return; - } - - finally { - if (keepPortablesMode != null) - keepPortablesMode.set(true); - } - msg.requestId(req.requestId()); - msg.clientId(req.clientId()); - msg.destinationId(req.destinationId()); - - if (msg instanceof GridClientResponse) - handleClientResponse(fut, (GridClientResponse)msg); + if (res0 instanceof GridClientResponse) + handleClientResponse(fut, (GridClientResponse)res0); else - log.warning("Unsupported response type received: " + msg); + log.warning("Unsupported response type received: " + res0); } } @@ -559,22 +526,7 @@ private void handleClientResponse(TcpClientFuture fut, GridClientResponse resp) req.requestId(resp.requestId()); - GridClientMessageWrapper wrapper; - - try { - wrapper = messageWrapper(req); - } - catch (IOException e) { - log.log(Level.SEVERE, "Failed to marshal message: " + req, e); - - removePending(resp.requestId()); - - fut.onDone(e); - - return; - } - - ses.send(wrapper); + ses.send(req); return; } @@ -588,22 +540,7 @@ private void handleClientResponse(TcpClientFuture fut, GridClientResponse resp) src.sessionToken(sesTok); - GridClientMessageWrapper wrapper; - - try { - wrapper = messageWrapper(src); - } - catch (IOException e) { - log.log(Level.SEVERE, "Failed to marshal message: " + src, e); - - removePending(resp.requestId()); - - fut.onDone(e); - - return; - } - - ses.send(wrapper); + ses.send(src); return; } @@ -623,27 +560,6 @@ else if (resp.errorMessage() != null) fut.onDone(resp.result()); } - /** - * @param msg Client message. - * @return Message wrapper for direct marshalling. - * @throws IOException If failed to marshal message. - */ - private GridClientMessageWrapper messageWrapper(GridClientMessage msg) throws IOException { - GridClientMessageWrapper wrapper = new GridClientMessageWrapper(); - - wrapper.requestId(msg.requestId()); - wrapper.clientId(clientId); - wrapper.destinationId(msg.destinationId()); - - ByteBuffer data = (msg instanceof GridRouterRequest) ? ByteBuffer.wrap(((GridRouterRequest)msg).body()) : - marsh.marshal(msg, 0); - - wrapper.message(data); - wrapper.messageSize(data.remaining() + 40); - - return wrapper; - } - /** * Removes pending request and signals to {@link #closedLatch} if necessary. * diff --git a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridRouterClientImpl.java b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridRouterClientImpl.java index 0d7f74d751f7f..1b3434612e79c 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridRouterClientImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridRouterClientImpl.java @@ -60,7 +60,7 @@ class GridRouterClientImpl implements GridClient { this.cliCfg = cliCfg; - clientImpl = new GridClientImpl(id, cliCfg); + clientImpl = new GridClientImpl(id, cliCfg, true); if (cliCfg.getProtocol() != GridClientProtocol.TCP) throw new AssertionError("Unknown protocol: " + cliCfg.getProtocol()); @@ -136,7 +136,7 @@ private GridClientConnectionManager connectionManager(byte marshId) throws GridC if (mgr == null) { GridClientConnectionManager old = connMgrMap.putIfAbsent(marshId, mgr = - clientImpl.newConnectionManager(marshId)); + clientImpl.newConnectionManager(marshId, true)); if (old != null) mgr = old; diff --git a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java index 231b0f52f48d0..129406dc332be 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java +++ b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java @@ -39,6 +39,12 @@ class GridTcpRouterNioParser extends GridTcpRestParser { /** Number of sent messages. */ private volatile long sndCnt; + /** + */ + public GridTcpRouterNioParser() { + super(false); + } + /** {@inheritDoc} */ @Override protected GridClientMessage parseClientMessage(GridNioSession ses, ParserState state) { rcvCnt++; diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index 212782c51a446..599059e93f0c2 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -25,7 +25,6 @@ import org.apache.ignite.cache.query.*; import org.apache.ignite.cache.store.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import org.apache.ignite.spi.indexing.*; import org.jetbrains.annotations.*; @@ -312,12 +311,6 @@ public class CacheConfiguration extends MutableConfiguration { /** */ private CacheInterceptor interceptor; - /** */ - private boolean portableEnabled; - - /** */ - private boolean keepPortableInStore = true; - /** Query configuration. */ private CacheQueryConfiguration qryCfg; @@ -379,7 +372,6 @@ public CacheConfiguration(CompleteConfiguration cfg) { invalidate = cc.isInvalidate(); isReadThrough = cc.isReadThrough(); isWriteThrough = cc.isWriteThrough(); - keepPortableInStore = cc.isKeepPortableInStore(); listenerConfigurations = cc.listenerConfigurations; loadPrevVal = cc.isLoadPreviousValue(); offHeapMaxMem = cc.getOffHeapMaxMemory(); @@ -389,7 +381,6 @@ public CacheConfiguration(CompleteConfiguration cfg) { name = cc.getName(); nearStartSize = cc.getNearStartSize(); nearEvictPlc = cc.getNearEvictionPolicy(); - portableEnabled = cc.isPortableEnabled(); preloadMode = cc.getPreloadMode(); preloadBatchSize = cc.getPreloadBatchSize(); preloadDelay = cc.getPreloadPartitionedDelay(); @@ -1603,61 +1594,6 @@ public void setInterceptor(CacheInterceptor interceptor) { this.interceptor = interceptor; } - /** - * Flag indicating whether Ignite should store portable keys and values - * as instances of {@link PortableObject}. - * - * @return Portable enabled flag. - */ - public boolean isPortableEnabled() { - return portableEnabled; - } - - /** - * Gets portable enabled flag value. - * - * @param portableEnabled Portable enabled flag value. - */ - public void setPortableEnabled(boolean portableEnabled) { - this.portableEnabled = portableEnabled; - } - - /** - * Flag indicating that {@link CacheStore} implementation - * is working with portable objects instead of Java objects - * if portable mode for this cache is enabled ({@link #isPortableEnabled()} - * flag is {@code true}). Default value of this flag is {@code true}, - * because this is recommended behavior from performance standpoint. - *

      - * If set to {@code false}, Ignite will deserialize keys and - * values stored in portable format before they are passed - * to cache store. - *

      - * Note that setting this flag to {@code false} can simplify - * store implementation in some cases, but it can cause performance - * degradation due to additional serializations and deserializations - * of portable objects. You will also need to have key and value - * classes on all nodes since portables will be deserialized when - * store is called. - *

      - * This flag is ignored if portable mode is disabled for this - * cache ({@link #isPortableEnabled()} flag is {@code false}). - * - * @return Keep portables in store flag. - */ - public boolean isKeepPortableInStore() { - return keepPortableInStore; - } - - /** - * Sets keep portables in store flag. - * - * @param keepPortableInStore Keep portables in store flag. - */ - public void setKeepPortableInStore(boolean keepPortableInStore) { - this.keepPortableInStore = keepPortableInStore; - } - /** * Gets collection of type metadata objects. * diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 2c3b8c07d8aa4..954ff86a3d6c4 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -29,7 +29,6 @@ import org.apache.ignite.services.*; import org.apache.ignite.marshaller.*; import org.apache.ignite.plugin.*; -import org.apache.ignite.portables.*; import org.apache.ignite.spi.authentication.*; import org.apache.ignite.spi.indexing.*; import org.apache.ignite.streamer.*; @@ -482,9 +481,6 @@ public class IgniteConfiguration { /** Client access configuration. */ private ClientConnectionConfiguration clientCfg; - /** Portable configuration. */ - private PortableConfiguration portableCfg; - /** Warmup closure. Will be invoked before actual grid start. */ private IgniteInClosure warmupClos; @@ -572,7 +568,6 @@ public IgniteConfiguration(IgniteConfiguration cfg) { p2pMissedCacheSize = cfg.getPeerClassLoadingMissedResourcesCacheSize(); p2pPoolSize = cfg.getPeerClassLoadingThreadPoolSize(); pluginCfgs = cfg.getPluginConfigurations(); - portableCfg = cfg.getPortableConfiguration(); qryCfg = cfg.getQueryConfiguration(); restAccessibleFolders = cfg.getRestAccessibleFolders(); restIdleTimeout = cfg.getRestIdleTimeout(); @@ -2775,20 +2770,6 @@ public void setClientConnectionConfiguration(ClientConnectionConfiguration clien this.clientCfg = clientCfg; } - /** - * @return Portable configuration. - */ - public PortableConfiguration getPortableConfiguration() { - return portableCfg; - } - - /** - * @param portableCfg Portable configuration. - */ - public void setPortableConfiguration(PortableConfiguration portableCfg) { - this.portableCfg = portableCfg; - } - /** * Gets configurations for services to be deployed on the grid. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java index d966434f35669..eb747125da775 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java @@ -555,6 +555,12 @@ private ClusterGroup forOthers(Collection excludeIds) { return forPredicate(new StreamersFilter(streamerName, streamerNames)); } + /** {@inheritDoc} */ + @Override public ClusterGroup forCacheNodes(@Nullable String cacheName, + Set distributionModes) { + return forPredicate(new CachesFilter(cacheName, distributionModes)); + } + /** {@inheritDoc} */ @Override public final ClusterGroup forHost(ClusterNode node) { A.notNull(node, "node"); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java index ac1fffabfb869..faaab85523f36 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java @@ -17,7 +17,9 @@ package org.apache.ignite.internal; +import org.apache.ignite.cache.*; import org.apache.ignite.cluster.*; +import org.jetbrains.annotations.*; import java.util.*; @@ -32,4 +34,11 @@ public interface ClusterGroupEx extends ClusterGroup { * @return Internal projection. */ public ClusterGroupEx forSubjectId(UUID subjId); + + /** + * @param cacheName Cache name. + * @param distributionModes Cache distribution modes. + * @return Cluster group. + */ + public ClusterGroup forCacheNodes(@Nullable String cacheName, Set distributionModes); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridDirectVersion.java b/modules/core/src/main/java/org/apache/ignite/internal/GridDirectVersion.java deleted file mode 100644 index b9566c54d8c0d..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridDirectVersion.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal; - -import java.lang.annotation.*; - -/** - * Assigns version to a field. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface GridDirectVersion { - /** - * @return Version index (must be above zero). - */ - int value(); -} 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 74019c19220aa..5cb6a27b1f77d 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 @@ -17,9 +17,9 @@ package org.apache.ignite.internal; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -28,7 +28,7 @@ /** * Job cancellation request. */ -public class GridJobCancelRequest extends GridTcpCommunicationMessageAdapter { +public class GridJobCancelRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -111,7 +111,7 @@ public boolean system() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridJobCancelRequest _clone = new GridJobCancelRequest(); clone0(_clone); @@ -120,7 +120,7 @@ public boolean system() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridJobCancelRequest _clone = (GridJobCancelRequest)_msg; _clone.sesId = sesId; @@ -131,33 +131,33 @@ public boolean system() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(jobId)) + if (!writer.writeIgniteUuid("jobId", jobId)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(sesId)) + if (!writer.writeIgniteUuid("sesId", sesId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putBoolean(sys)) + if (!writer.writeBoolean("sys", sys)) return false; - commState.idx++; + state++; } @@ -167,36 +167,32 @@ public boolean system() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid jobId0 = commState.getGridUuid(); + jobId = reader.readIgniteUuid("jobId"); - if (jobId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - jobId = jobId0; - - commState.idx++; + state++; case 1: - IgniteUuid sesId0 = commState.getGridUuid(); + sesId = reader.readIgniteUuid("sesId"); - if (sesId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - sesId = sesId0; - - commState.idx++; + state++; case 2: - if (buf.remaining() < 1) - return false; + sys = reader.readBoolean("sys"); - sys = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } 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 4bf76a164b702..004b9955f00b5 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 @@ -19,10 +19,10 @@ import org.apache.ignite.compute.*; import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -32,7 +32,7 @@ /** * Job execution request. */ -public class GridJobExecuteRequest extends GridTcpCommunicationMessageAdapter implements GridTaskMessage { +public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMessage { /** */ private static final long serialVersionUID = 0L; @@ -413,7 +413,7 @@ public UUID getSubjectId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridJobExecuteRequest _clone = new GridJobExecuteRequest(); clone0(_clone); @@ -422,7 +422,7 @@ public UUID getSubjectId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridJobExecuteRequest _clone = (GridJobExecuteRequest)_msg; _clone.subjId = subjId; @@ -456,194 +456,141 @@ public UUID getSubjectId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(clsLdrId)) + if (!writer.writeIgniteUuid("clsLdrId", clsLdrId)) return false; - commState.idx++; + state++; case 1: - if (!commState.putString(cpSpi)) + if (!writer.writeString("cpSpi", cpSpi)) return false; - commState.idx++; + state++; case 2: - if (!commState.putEnum(depMode)) + if (!writer.writeEnum("depMode", depMode)) return false; - commState.idx++; + state++; case 3: - if (!commState.putBoolean(dynamicSiblings)) + if (!writer.writeBoolean("dynamicSiblings", dynamicSiblings)) return false; - commState.idx++; + state++; case 4: - if (!commState.putBoolean(forceLocDep)) + if (!writer.writeBoolean("forceLocDep", forceLocDep)) return false; - commState.idx++; + state++; case 5: - if (!commState.putBoolean(internal)) + if (!writer.writeBoolean("internal", internal)) return false; - commState.idx++; + state++; case 6: - if (!commState.putByteArray(jobAttrsBytes)) + if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes)) return false; - commState.idx++; + state++; case 7: - if (!commState.putByteArray(jobBytes)) + if (!writer.writeByteArray("jobBytes", jobBytes)) return false; - commState.idx++; + state++; case 8: - if (!commState.putGridUuid(jobId)) + if (!writer.writeIgniteUuid("jobId", jobId)) return false; - commState.idx++; + state++; case 9: - if (ldrParticipants != null) { - if (commState.it == null) { - if (!commState.putInt(ldrParticipants.size())) - return false; - - commState.it = ldrParticipants.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putUuid(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putGridUuid(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("ldrParticipants", ldrParticipants, UUID.class, IgniteUuid.class)) + return false; - commState.idx++; + state++; case 10: - if (!commState.putByteArray(sesAttrsBytes)) + if (!writer.writeByteArray("sesAttrsBytes", sesAttrsBytes)) return false; - commState.idx++; + state++; case 11: - if (!commState.putBoolean(sesFullSup)) + if (!writer.writeBoolean("sesFullSup", sesFullSup)) return false; - commState.idx++; + state++; case 12: - if (!commState.putGridUuid(sesId)) + if (!writer.writeIgniteUuid("sesId", sesId)) return false; - commState.idx++; + state++; case 13: - if (!commState.putByteArray(siblingsBytes)) + if (!writer.writeByteArray("siblingsBytes", siblingsBytes)) return false; - commState.idx++; + state++; case 14: - if (!commState.putLong(startTaskTime)) + if (!writer.writeLong("startTaskTime", startTaskTime)) return false; - commState.idx++; + state++; case 15: - if (!commState.putUuid(subjId)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 16: - if (!commState.putString(taskClsName)) + if (!writer.writeString("taskClsName", taskClsName)) return false; - commState.idx++; + state++; case 17: - if (!commState.putString(taskName)) + if (!writer.writeString("taskName", taskName)) return false; - commState.idx++; + state++; case 18: - if (!commState.putLong(timeout)) + if (!writer.writeLong("timeout", timeout)) return false; - commState.idx++; + state++; case 19: - if (top != null) { - if (commState.it == null) { - if (!commState.putInt(top.size())) - return false; - - commState.it = top.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putUuid((UUID)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("top", top, UUID.class)) + return false; - commState.idx++; + state++; case 20: - if (!commState.putString(userVer)) + if (!writer.writeString("userVer", userVer)) return false; - commState.idx++; + state++; } @@ -653,257 +600,176 @@ public UUID getSubjectId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid clsLdrId0 = commState.getGridUuid(); + clsLdrId = reader.readIgniteUuid("clsLdrId"); - if (clsLdrId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - clsLdrId = clsLdrId0; - - commState.idx++; + state++; case 1: - String cpSpi0 = commState.getString(); + cpSpi = reader.readString("cpSpi"); - if (cpSpi0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - cpSpi = cpSpi0; - - commState.idx++; + state++; case 2: - if (buf.remaining() < 1) - return false; - - byte depMode0 = commState.getByte(); + depMode = reader.readEnum("depMode", DeploymentMode.class); - depMode = DeploymentMode.fromOrdinal(depMode0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - if (buf.remaining() < 1) - return false; + dynamicSiblings = reader.readBoolean("dynamicSiblings"); - dynamicSiblings = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (buf.remaining() < 1) - return false; + forceLocDep = reader.readBoolean("forceLocDep"); - forceLocDep = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - if (buf.remaining() < 1) - return false; + internal = reader.readBoolean("internal"); - internal = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 6: - byte[] jobAttrsBytes0 = commState.getByteArray(); + jobAttrsBytes = reader.readByteArray("jobAttrsBytes"); - if (jobAttrsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - jobAttrsBytes = jobAttrsBytes0; - - commState.idx++; + state++; case 7: - byte[] jobBytes0 = commState.getByteArray(); + jobBytes = reader.readByteArray("jobBytes"); - if (jobBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - jobBytes = jobBytes0; - - commState.idx++; + state++; case 8: - IgniteUuid jobId0 = commState.getGridUuid(); + jobId = reader.readIgniteUuid("jobId"); - if (jobId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - jobId = jobId0; - - commState.idx++; + state++; case 9: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + ldrParticipants = reader.readMap("ldrParticipants", UUID.class, IgniteUuid.class, false); - if (commState.readSize >= 0) { - if (ldrParticipants == null) - ldrParticipants = new HashMap<>(commState.readSize, 1.0f); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } - - IgniteUuid _val = commState.getGridUuid(); - - if (_val == GRID_UUID_NOT_READ) - return false; - - ldrParticipants.put((UUID)commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 10: - byte[] sesAttrsBytes0 = commState.getByteArray(); + sesAttrsBytes = reader.readByteArray("sesAttrsBytes"); - if (sesAttrsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - sesAttrsBytes = sesAttrsBytes0; - - commState.idx++; + state++; case 11: - if (buf.remaining() < 1) - return false; + sesFullSup = reader.readBoolean("sesFullSup"); - sesFullSup = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 12: - IgniteUuid sesId0 = commState.getGridUuid(); + sesId = reader.readIgniteUuid("sesId"); - if (sesId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - sesId = sesId0; - - commState.idx++; + state++; case 13: - byte[] siblingsBytes0 = commState.getByteArray(); + siblingsBytes = reader.readByteArray("siblingsBytes"); - if (siblingsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - siblingsBytes = siblingsBytes0; - - commState.idx++; + state++; case 14: - if (buf.remaining() < 8) - return false; + startTaskTime = reader.readLong("startTaskTime"); - startTaskTime = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 15: - UUID subjId0 = commState.getUuid(); + subjId = reader.readUuid("subjId"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 16: - String taskClsName0 = commState.getString(); + taskClsName = reader.readString("taskClsName"); - if (taskClsName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - taskClsName = taskClsName0; - - commState.idx++; + state++; case 17: - String taskName0 = commState.getString(); + taskName = reader.readString("taskName"); - if (taskName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - taskName = taskName0; - - commState.idx++; + state++; case 18: - if (buf.remaining() < 8) - return false; + timeout = reader.readLong("timeout"); - timeout = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 19: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + top = reader.readCollection("top", UUID.class); - if (commState.readSize >= 0) { - if (top == null) - top = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - top.add((UUID)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 20: - String userVer0 = commState.getString(); + userVer = reader.readString("userVer"); - if (userVer0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - userVer = userVer0; - - commState.idx++; + state++; } @@ -912,7 +778,7 @@ public UUID getSubjectId() { /** {@inheritDoc} */ @Override public byte directType() { - return 81; + return 1; } /** {@inheritDoc} */ 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 dec23989b6afd..3c3352a72b469 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 @@ -18,10 +18,10 @@ package org.apache.ignite.internal; import org.apache.ignite.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -31,7 +31,7 @@ /** * Job execution response. */ -public class GridJobExecuteResponse extends GridTcpCommunicationMessageAdapter implements GridTaskMessage { +public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMessage { /** */ private static final long serialVersionUID = 0L; @@ -206,7 +206,7 @@ public void setFakeException(IgniteException fakeEx) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridJobExecuteResponse _clone = new GridJobExecuteResponse(); clone0(_clone); @@ -215,7 +215,7 @@ public void setFakeException(IgniteException fakeEx) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridJobExecuteResponse _clone = (GridJobExecuteResponse)_msg; _clone.nodeId = nodeId; @@ -234,57 +234,57 @@ public void setFakeException(IgniteException fakeEx) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(gridExBytes)) + if (!writer.writeByteArray("gridExBytes", gridExBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putBoolean(isCancelled)) + if (!writer.writeBoolean("isCancelled", isCancelled)) return false; - commState.idx++; + state++; case 2: - if (!commState.putByteArray(jobAttrsBytes)) + if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes)) return false; - commState.idx++; + state++; case 3: - if (!commState.putGridUuid(jobId)) + if (!writer.writeIgniteUuid("jobId", jobId)) return false; - commState.idx++; + state++; case 4: - if (!commState.putUuid(nodeId)) + if (!writer.writeUuid("nodeId", nodeId)) return false; - commState.idx++; + state++; case 5: - if (!commState.putByteArray(resBytes)) + if (!writer.writeByteArray("resBytes", resBytes)) return false; - commState.idx++; + state++; case 6: - if (!commState.putGridUuid(sesId)) + if (!writer.writeIgniteUuid("sesId", sesId)) return false; - commState.idx++; + state++; } @@ -294,76 +294,64 @@ public void setFakeException(IgniteException fakeEx) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - byte[] gridExBytes0 = commState.getByteArray(); + gridExBytes = reader.readByteArray("gridExBytes"); - if (gridExBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - gridExBytes = gridExBytes0; - - commState.idx++; + state++; case 1: - if (buf.remaining() < 1) - return false; + isCancelled = reader.readBoolean("isCancelled"); - isCancelled = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - byte[] jobAttrsBytes0 = commState.getByteArray(); + jobAttrsBytes = reader.readByteArray("jobAttrsBytes"); - if (jobAttrsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - jobAttrsBytes = jobAttrsBytes0; - - commState.idx++; + state++; case 3: - IgniteUuid jobId0 = commState.getGridUuid(); + jobId = reader.readIgniteUuid("jobId"); - if (jobId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - jobId = jobId0; - - commState.idx++; + state++; case 4: - UUID nodeId0 = commState.getUuid(); + nodeId = reader.readUuid("nodeId"); - if (nodeId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - nodeId = nodeId0; - - commState.idx++; + state++; case 5: - byte[] resBytes0 = commState.getByteArray(); + resBytes = reader.readByteArray("resBytes"); - if (resBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - resBytes = resBytes0; - - commState.idx++; + state++; case 6: - IgniteUuid sesId0 = commState.getGridUuid(); + sesId = reader.readIgniteUuid("sesId"); - if (sesId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - sesId = sesId0; - - commState.idx++; + state++; } 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 bced3666b39be..2fc71d9912c6c 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 @@ -17,9 +17,9 @@ package org.apache.ignite.internal; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -27,7 +27,7 @@ /** * Job siblings request. */ -public class GridJobSiblingsRequest extends GridTcpCommunicationMessageAdapter { +public class GridJobSiblingsRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -85,7 +85,7 @@ public byte[] topicBytes() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridJobSiblingsRequest _clone = new GridJobSiblingsRequest(); clone0(_clone); @@ -94,7 +94,7 @@ public byte[] topicBytes() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridJobSiblingsRequest _clone = (GridJobSiblingsRequest)_msg; _clone.sesId = sesId; @@ -105,27 +105,27 @@ public byte[] topicBytes() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(sesId)) + if (!writer.writeIgniteUuid("sesId", sesId)) return false; - commState.idx++; + state++; case 1: - if (!commState.putByteArray(topicBytes)) + if (!writer.writeByteArray("topicBytes", topicBytes)) return false; - commState.idx++; + state++; } @@ -135,28 +135,24 @@ public byte[] topicBytes() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid sesId0 = commState.getGridUuid(); + sesId = reader.readIgniteUuid("sesId"); - if (sesId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - sesId = sesId0; - - commState.idx++; + state++; case 1: - byte[] topicBytes0 = commState.getByteArray(); + topicBytes = reader.readByteArray("topicBytes"); - if (topicBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - topicBytes = topicBytes0; - - commState.idx++; + state++; } 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 4d52bd5ee37fd..ffaaa1ef8cd10 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 @@ -19,9 +19,9 @@ import org.apache.ignite.*; import org.apache.ignite.compute.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.marshaller.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -31,7 +31,7 @@ /** * Job siblings response. */ -public class GridJobSiblingsResponse extends GridTcpCommunicationMessageAdapter { +public class GridJobSiblingsResponse extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -78,7 +78,7 @@ public void unmarshalSiblings(Marshaller marsh) throws IgniteCheckedException { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridJobSiblingsResponse _clone = new GridJobSiblingsResponse(); clone0(_clone); @@ -87,7 +87,7 @@ public void unmarshalSiblings(Marshaller marsh) throws IgniteCheckedException { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridJobSiblingsResponse _clone = (GridJobSiblingsResponse)_msg; _clone.siblings = siblings; @@ -97,21 +97,21 @@ public void unmarshalSiblings(Marshaller marsh) throws IgniteCheckedException { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(siblingsBytes)) + if (!writer.writeByteArray("siblingsBytes", siblingsBytes)) return false; - commState.idx++; + state++; } @@ -121,18 +121,16 @@ public void unmarshalSiblings(Marshaller marsh) throws IgniteCheckedException { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - byte[] siblingsBytes0 = commState.getByteArray(); + siblingsBytes = reader.readByteArray("siblingsBytes"); - if (siblingsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - siblingsBytes = siblingsBytes0; - - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java index eea69ae2807d7..152cfa67003af 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java @@ -59,7 +59,6 @@ import org.apache.ignite.internal.processors.task.*; import org.apache.ignite.internal.processors.timeout.*; import org.apache.ignite.internal.product.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.plugin.*; @@ -502,17 +501,6 @@ public interface GridKernalContext extends Iterable { */ public T createComponent(Class cls); - /** - * @return Message factory. - */ - public GridTcpMessageFactory messageFactory(); - - /** - * @param producer Message producer. - * @return Message type code. - */ - public byte registerMessageProducer(GridTcpCommunicationMessageProducer producer); - /** * @return Thread pool implementation to be used in grid to process job execution * requests and user messages sent to the node. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java index c9604de056675..3bd3f7cd06978 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java @@ -35,6 +35,7 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.dr.*; import org.apache.ignite.internal.processors.cache.dr.os.*; +import org.apache.ignite.internal.processors.cache.serialization.*; import org.apache.ignite.internal.processors.clock.*; import org.apache.ignite.internal.processors.closure.*; import org.apache.ignite.internal.processors.continuous.*; @@ -50,6 +51,7 @@ import org.apache.ignite.internal.processors.plugin.*; import org.apache.ignite.internal.processors.port.*; import org.apache.ignite.internal.processors.portable.*; +import org.apache.ignite.internal.processors.portable.os.*; import org.apache.ignite.internal.processors.query.*; import org.apache.ignite.internal.processors.resource.*; import org.apache.ignite.internal.processors.rest.*; @@ -62,7 +64,6 @@ import org.apache.ignite.internal.processors.task.*; import org.apache.ignite.internal.processors.timeout.*; import org.apache.ignite.internal.product.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -317,15 +318,6 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable /** Enterprise release flag. */ private boolean ent; - /** */ - private GridTcpMessageFactory msgFactory; - - /** */ - private int pluginMsg = GridTcpCommunicationMessageFactory.MAX_COMMON_TYPE; - - /** */ - private Map pluginMsgs; - /** * No-arg constructor is required by externalization. */ @@ -844,69 +836,14 @@ public void timeSource(GridClockSource clockSrc) { if (cls.equals(GridCacheDrManager.class)) return (T)new GridOsCacheDrManager(); + else if (cls.equals(GridPortableProcessor.class)) + return (T)new GridOsPortableProcessor(this); + else if (cls.equals(IgniteCacheSerializationManager.class)) + return (T)new IgniteCacheOsSerializationManager(); throw new IgniteException("Unsupported component type: " + cls); } - /** {@inheritDoc} */ - @Override public GridTcpMessageFactory messageFactory() { - assert msgFactory != null; - - return msgFactory; - } - - /** {@inheritDoc} */ - @Override public byte registerMessageProducer(GridTcpCommunicationMessageProducer producer) { - int nextMsg = ++pluginMsg; - - if (nextMsg > Byte.MAX_VALUE) - throw new IgniteException(); - - if (pluginMsgs == null) - pluginMsgs = new HashMap<>(); - - pluginMsgs.put((byte)nextMsg, producer); - - return (byte)nextMsg; - } - - /** - * Creates message factory. - */ - void createMessageFactory() { - final GridTcpCommunicationMessageProducer[] common = GridTcpCommunicationMessageFactory.commonProducers(); - - final GridTcpCommunicationMessageProducer[] producers; - - if (pluginMsgs != null) { - producers = Arrays.copyOf(common, pluginMsg + 1); - - for (Map.Entry e : pluginMsgs.entrySet()) { - assert producers[e.getKey()] == null : e.getKey(); - - producers[e.getKey()] = e.getValue(); - } - - pluginMsgs = null; - } - else - producers = common; - - msgFactory = new GridTcpMessageFactory() { - @Override public GridTcpCommunicationMessageAdapter create(byte type) { - if (type < 0 || type >= producers.length) - return GridTcpCommunicationMessageFactory.create(type); - - GridTcpCommunicationMessageProducer producer = producers[type]; - - if (producer != null) - return producer.create(type); - else - throw new IllegalStateException("Common message type producer is not registered: " + type); - } - }; - } - /** * @return Plugin manager. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridPluginContext.java b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginContext.java index b9f7e2d573cf0..31a4246bf5ef7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridPluginContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginContext.java @@ -20,7 +20,6 @@ import org.apache.ignite.*; import org.apache.ignite.cluster.*; import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.plugin.*; import org.apache.ignite.spi.*; @@ -93,9 +92,4 @@ public GridPluginContext(GridKernalContext ctx, PluginConfiguration cfg, IgniteC @Override public void deregisterPorts(Class cls) { ctx.ports().deregisterPorts(cls); } - - /** {@inheritDoc} */ - @Override public byte registerMessageProducer(GridTcpCommunicationMessageProducer producer) { - return ctx.registerMessageProducer(producer); - } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridPortablesImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridPortablesImpl.java deleted file mode 100644 index 8dedc4dadf1eb..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridPortablesImpl.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal; - -import org.apache.ignite.*; -import org.apache.ignite.internal.processors.portable.*; -import org.apache.ignite.portables.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * {@link org.apache.ignite.IgnitePortables} implementation. - */ -public class GridPortablesImpl implements IgnitePortables { - /** */ - private GridKernalContext ctx; - - /** */ - private GridPortableProcessor proc; - - /** - * @param ctx Context. - */ - public GridPortablesImpl(GridKernalContext ctx) { - this.ctx = ctx; - - proc = ctx.portable(); - } - - /** {@inheritDoc} */ - @Override public int typeId(String typeName) { - guard(); - - try { - return proc.typeId(typeName); - } - finally { - unguard(); - } - } - - /** {@inheritDoc} */ - @Override public T toPortable(@Nullable Object obj) throws PortableException { - guard(); - - try { - return (T)proc.marshalToPortable(obj); - } - finally { - unguard(); - } - } - - /** {@inheritDoc} */ - @Override public PortableBuilder builder(int typeId) { - guard(); - - try { - return proc.builder(typeId); - } - finally { - unguard(); - } - } - - /** {@inheritDoc} */ - @Override public PortableBuilder builder(String typeName) { - guard(); - - try { - return proc.builder(typeName); - } - finally { - unguard(); - } - } - - /** {@inheritDoc} */ - @Override public PortableBuilder builder(PortableObject portableObj) { - guard(); - - try { - return proc.builder(portableObj); - } - finally { - unguard(); - } - } - - /** {@inheritDoc} */ - @Nullable @Override public PortableMetadata metadata(Class cls) throws PortableException { - guard(); - - try { - return proc.metadata(proc.typeId(cls.getName())); - } - finally { - unguard(); - } - } - - /** {@inheritDoc} */ - @Nullable @Override public PortableMetadata metadata(String typeName) throws PortableException { - guard(); - - try { - return proc.metadata(proc.typeId(typeName)); - } - finally { - unguard(); - } - } - - /** {@inheritDoc} */ - @Nullable @Override public PortableMetadata metadata(int typeId) throws PortableException { - guard(); - - try { - return proc.metadata(typeId); - } - finally { - unguard(); - } - } - - /** {@inheritDoc} */ - @Override public Collection metadata() throws PortableException { - guard(); - - try { - return proc.metadata(); - } - finally { - unguard(); - } - } - - /** - * @return Portable processor. - */ - public GridPortableProcessor processor() { - return proc; - } - - /** - * ctx.gateway().readLock() - */ - private void guard() { - ctx.gateway().readLock(); - } - - /** - * ctx.gateway().readUnlock() - */ - private void unguard() { - ctx.gateway().readUnlock(); - } -} 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 40ce0f623362e..75ff8eabec6a7 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 @@ -17,9 +17,9 @@ package org.apache.ignite.internal; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -27,7 +27,7 @@ /** * Request for cancelling tasks. */ -public class GridTaskCancelRequest extends GridTcpCommunicationMessageAdapter { +public class GridTaskCancelRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -62,7 +62,7 @@ public IgniteUuid sessionId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridTaskCancelRequest _clone = new GridTaskCancelRequest(); clone0(_clone); @@ -71,7 +71,7 @@ public IgniteUuid sessionId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridTaskCancelRequest _clone = (GridTaskCancelRequest)_msg; _clone.sesId = sesId; @@ -80,21 +80,21 @@ public IgniteUuid sessionId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(sesId)) + if (!writer.writeIgniteUuid("sesId", sesId)) return false; - commState.idx++; + state++; } @@ -104,18 +104,16 @@ public IgniteUuid sessionId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid sesId0 = commState.getGridUuid(); + sesId = reader.readIgniteUuid("sesId"); - if (sesId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - sesId = sesId0; - - commState.idx++; + state++; } 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 c219679d81861..1f75ee2bfe3af 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 @@ -17,9 +17,9 @@ package org.apache.ignite.internal; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -28,7 +28,7 @@ /** * Task session request. */ -public class GridTaskSessionRequest extends GridTcpCommunicationMessageAdapter implements GridTaskMessage { +public class GridTaskSessionRequest extends MessageAdapter implements GridTaskMessage { /** */ private static final long serialVersionUID = 0L; @@ -99,7 +99,7 @@ public IgniteUuid getJobId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridTaskSessionRequest _clone = new GridTaskSessionRequest(); clone0(_clone); @@ -108,7 +108,7 @@ public IgniteUuid getJobId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridTaskSessionRequest _clone = (GridTaskSessionRequest)_msg; _clone.sesId = sesId; @@ -120,33 +120,33 @@ public IgniteUuid getJobId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(attrsBytes)) + if (!writer.writeByteArray("attrsBytes", attrsBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(jobId)) + if (!writer.writeIgniteUuid("jobId", jobId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putGridUuid(sesId)) + if (!writer.writeIgniteUuid("sesId", sesId)) return false; - commState.idx++; + state++; } @@ -156,38 +156,32 @@ public IgniteUuid getJobId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - byte[] attrsBytes0 = commState.getByteArray(); + attrsBytes = reader.readByteArray("attrsBytes"); - if (attrsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - attrsBytes = attrsBytes0; - - commState.idx++; + state++; case 1: - IgniteUuid jobId0 = commState.getGridUuid(); + jobId = reader.readIgniteUuid("jobId"); - if (jobId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - jobId = jobId0; - - commState.idx++; + state++; case 2: - IgniteUuid sesId0 = commState.getGridUuid(); + sesId = reader.readIgniteUuid("sesId"); - if (sesId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - sesId = sesId0; - - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index 917032f9ffe49..d2dced156afaf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -212,10 +212,6 @@ public class IgniteKernal extends ClusterGroupAdapter implements IgniteEx, Ignit @GridToStringExclude private GridSecurity security; - /** Portables instance. */ - @GridToStringExclude - private IgnitePortables portables; - /** Kernal gateway. */ @GridToStringExclude private final AtomicReference gw = new AtomicReference<>(); @@ -750,13 +746,13 @@ public void start(final IgniteConfiguration cfg, ExecutorService utilityCachePoo startProcessor(ctx, createComponent(GridLicenseProcessor.class, ctx), attrs); startProcessor(ctx, new GridAffinityProcessor(ctx), attrs); startProcessor(ctx, createComponent(GridSegmentationProcessor.class, ctx), attrs); + startProcessor(ctx, createComponent(GridPortableProcessor.class, ctx), attrs); startProcessor(ctx, new GridQueryProcessor(ctx), attrs); startProcessor(ctx, new GridCacheProcessor(ctx), attrs); startProcessor(ctx, new GridTaskSessionProcessor(ctx), attrs); startProcessor(ctx, new GridJobProcessor(ctx), attrs); startProcessor(ctx, new GridTaskProcessor(ctx), attrs); startProcessor(ctx, (GridProcessor)SCHEDULE.createOptional(ctx), attrs); - startProcessor(ctx, createComponent(GridPortableProcessor.class, ctx), attrs); startProcessor(ctx, new GridRestProcessor(ctx), attrs); startProcessor(ctx, new GridDataLoaderProcessor(ctx), attrs); startProcessor(ctx, new GridStreamProcessor(ctx), attrs); @@ -775,11 +771,8 @@ public void start(final IgniteConfiguration cfg, ExecutorService utilityCachePoo provider.start(ctx.plugins().pluginContextForProvider(provider), attrs); } - ctx.createMessageFactory(); - if (ctx.isEnterprise()) { security = new GridSecurityImpl(ctx); - portables = new GridPortablesImpl(ctx); } gw.writeLock(); @@ -3249,14 +3242,6 @@ private boolean runNextNodeCallable(final ConcurrentLinkedQueue compatibleVersions() { return compatibleVers; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 7ef3c15a3f256..8040f2c4ea0a3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -1678,9 +1678,6 @@ else if (marsh instanceof OptimizedMarshaller && !U.isHotSpot()) { // REST configuration. myCfg.setClientConnectionConfiguration(clientCfg); - // Portable configuration. - myCfg.setPortableConfiguration(cfg.getPortableConfiguration()); - // Hadoop configuration. myCfg.setHadoopConfiguration(cfg.getHadoopConfiguration()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java new file mode 100644 index 0000000000000..f74da650856d6 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java @@ -0,0 +1,1613 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.direct; + +import org.apache.ignite.internal.util.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; +import org.jetbrains.annotations.*; +import sun.misc.*; +import sun.nio.ch.*; + +import java.lang.reflect.*; +import java.nio.*; +import java.util.*; + +/** + * Portable stream based on {@link ByteBuffer}. + */ +public class DirectByteBufferStream { + /** */ + private static final Unsafe UNSAFE = GridUnsafe.unsafe(); + + /** */ + private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class); + + /** */ + private static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class); + + /** */ + private static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class); + + /** */ + private static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class); + + /** */ + private static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class); + + /** */ + private static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class); + + /** */ + private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class); + + /** */ + private static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class); + + /** */ + private static final byte[] BYTE_ARR_EMPTY = new byte[0]; + + /** */ + private static final short[] SHORT_ARR_EMPTY = new short[0]; + + /** */ + private static final int[] INT_ARR_EMPTY = new int[0]; + + /** */ + private static final long[] LONG_ARR_EMPTY = new long[0]; + + /** */ + private static final float[] FLOAT_ARR_EMPTY = new float[0]; + + /** */ + private static final double[] DOUBLE_ARR_EMPTY = new double[0]; + + /** */ + private static final char[] CHAR_ARR_EMPTY = new char[0]; + + /** */ + private static final boolean[] BOOLEAN_ARR_EMPTY = new boolean[0]; + + /** */ + private static final ArrayCreator BYTE_ARR_CREATOR = new ArrayCreator() { + @Override public byte[] create(int len) { + assert len >= 0; + + switch (len) { + case 0: + return BYTE_ARR_EMPTY; + + default: + return new byte[len]; + } + } + }; + + /** */ + private static final ArrayCreator SHORT_ARR_CREATOR = new ArrayCreator() { + @Override public short[] create(int len) { + assert len >= 0; + + switch (len) { + case 0: + return SHORT_ARR_EMPTY; + + default: + return new short[len]; + } + } + }; + + /** */ + private static final ArrayCreator INT_ARR_CREATOR = new ArrayCreator() { + @Override public int[] create(int len) { + assert len >= 0; + + switch (len) { + case 0: + return INT_ARR_EMPTY; + + default: + return new int[len]; + } + } + }; + + /** */ + private static final ArrayCreator LONG_ARR_CREATOR = new ArrayCreator() { + @Override public long[] create(int len) { + assert len >= 0; + + switch (len) { + case 0: + return LONG_ARR_EMPTY; + + default: + return new long[len]; + } + } + }; + + /** */ + private static final ArrayCreator FLOAT_ARR_CREATOR = new ArrayCreator() { + @Override public float[] create(int len) { + assert len >= 0; + + switch (len) { + case 0: + return FLOAT_ARR_EMPTY; + + default: + return new float[len]; + } + } + }; + + /** */ + private static final ArrayCreator DOUBLE_ARR_CREATOR = new ArrayCreator() { + @Override public double[] create(int len) { + assert len >= 0; + + switch (len) { + case 0: + return DOUBLE_ARR_EMPTY; + + default: + return new double[len]; + } + } + }; + + /** */ + private static final ArrayCreator CHAR_ARR_CREATOR = new ArrayCreator() { + @Override public char[] create(int len) { + assert len >= 0; + + switch (len) { + case 0: + return CHAR_ARR_EMPTY; + + default: + return new char[len]; + } + } + }; + + /** */ + private static final ArrayCreator BOOLEAN_ARR_CREATOR = new ArrayCreator() { + @Override public boolean[] create(int len) { + assert len >= 0; + + switch (len) { + case 0: + return BOOLEAN_ARR_EMPTY; + + default: + return new boolean[len]; + } + } + }; + + /** */ + private static final Object NULL = new Object(); + + /** */ + private static final Map, Type> TYPES = U.newHashMap(30); + + static { + TYPES.put(byte.class, Type.BYTE); + TYPES.put(Byte.class, Type.BYTE); + TYPES.put(short.class, Type.SHORT); + TYPES.put(Short.class, Type.SHORT); + TYPES.put(int.class, Type.INT); + TYPES.put(Integer.class, Type.INT); + TYPES.put(long.class, Type.LONG); + TYPES.put(Long.class, Type.LONG); + TYPES.put(float.class, Type.FLOAT); + TYPES.put(Float.class, Type.FLOAT); + TYPES.put(double.class, Type.DOUBLE); + TYPES.put(Double.class, Type.DOUBLE); + TYPES.put(char.class, Type.CHAR); + TYPES.put(Character.class, Type.CHAR); + TYPES.put(boolean.class, Type.BOOLEAN); + TYPES.put(Boolean.class, Type.BOOLEAN); + TYPES.put(byte[].class, Type.BYTE_ARR); + TYPES.put(short[].class, Type.SHORT_ARR); + TYPES.put(int[].class, Type.INT_ARR); + TYPES.put(long[].class, Type.LONG_ARR); + TYPES.put(float[].class, Type.FLOAT_ARR); + TYPES.put(double[].class, Type.DOUBLE_ARR); + TYPES.put(char[].class, Type.CHAR_ARR); + TYPES.put(boolean[].class, Type.BOOLEAN_ARR); + TYPES.put(String.class, Type.STRING); + TYPES.put(BitSet.class, Type.BIT_SET); + TYPES.put(UUID.class, Type.UUID); + TYPES.put(IgniteUuid.class, Type.IGNITE_UUID); + } + + /** + * @param cls Class. + * @return Type enum value. + */ + private static Type type(Class cls) { + Type type = TYPES.get(cls); + + if (type == null) { + assert MessageAdapter.class.isAssignableFrom(cls) : cls; + + type = Type.MSG; + } + + return type; + } + + /** */ + private final MessageFactory msgFactory; + + /** */ + private ByteBuffer buf; + + /** */ + private byte[] heapArr; + + /** */ + private long baseOff; + + /** */ + private int arrOff = -1; + + /** */ + private Object tmpArr; + + /** */ + private int tmpArrOff; + + /** */ + private int tmpArrBytes; + + /** */ + private boolean msgTypeDone; + + /** */ + private MessageAdapter msg; + + /** */ + private Iterator it; + + /** */ + private Object cur = NULL; + + /** */ + private boolean keyDone; + + /** */ + private int readSize = -1; + + /** */ + private int readItems; + + /** */ + private Object[] objArr; + + /** */ + private Collection col; + + /** */ + private Map map; + + /** */ + private boolean lastFinished; + + /** + * @param msgFactory Message factory. + */ + public DirectByteBufferStream(@Nullable MessageFactory msgFactory) { + this.msgFactory = msgFactory; + } + + /** + * @param buf Buffer. + */ + public void setBuffer(ByteBuffer buf) { + assert buf != null; + + if (this.buf != buf) { + this.buf = buf; + + heapArr = buf.isDirect() ? null : buf.array(); + baseOff = buf.isDirect() ? ((DirectBuffer)buf).address() : BYTE_ARR_OFF; + } + } + + /** + * @return Number of remaining bytes. + */ + public int remaining() { + return buf.remaining(); + } + + /** + * @return Whether last object was fully written or read. + */ + public boolean lastFinished() { + return lastFinished; + } + + /** + * @param val Value. + */ + public void writeByte(byte val) { + lastFinished = buf.remaining() >= 1; + + if (lastFinished) { + int pos = buf.position(); + + UNSAFE.putByte(heapArr, baseOff + pos, val); + + buf.position(pos + 1); + } + } + + /** + * @param val Value. + */ + public void writeShort(short val) { + lastFinished = buf.remaining() >= 2; + + if (lastFinished) { + int pos = buf.position(); + + UNSAFE.putShort(heapArr, baseOff + pos, val); + + buf.position(pos + 2); + } + } + + /** + * @param val Value. + */ + public void writeInt(int val) { + lastFinished = buf.remaining() >= 4; + + if (lastFinished) { + int pos = buf.position(); + + UNSAFE.putInt(heapArr, baseOff + pos, val); + + buf.position(pos + 4); + } + } + + /** + * @param val Value. + */ + public void writeLong(long val) { + lastFinished = buf.remaining() >= 8; + + if (lastFinished) { + int pos = buf.position(); + + UNSAFE.putLong(heapArr, baseOff + pos, val); + + buf.position(pos + 8); + } + } + + /** + * @param val Value. + */ + public void writeFloat(float val) { + lastFinished = buf.remaining() >= 4; + + if (lastFinished) { + int pos = buf.position(); + + UNSAFE.putFloat(heapArr, baseOff + pos, val); + + buf.position(pos + 4); + } + } + + /** + * @param val Value. + */ + public void writeDouble(double val) { + lastFinished = buf.remaining() >= 8; + + if (lastFinished) { + int pos = buf.position(); + + UNSAFE.putDouble(heapArr, baseOff + pos, val); + + buf.position(pos + 8); + } + } + + /** + * @param val Value. + */ + public void writeChar(char val) { + lastFinished = buf.remaining() >= 2; + + if (lastFinished) { + int pos = buf.position(); + + UNSAFE.putChar(heapArr, baseOff + pos, val); + + buf.position(pos + 2); + } + } + + /** + * @param val Value. + */ + public void writeBoolean(boolean val) { + lastFinished = buf.remaining() >= 1; + + if (lastFinished) { + int pos = buf.position(); + + UNSAFE.putBoolean(heapArr, baseOff + pos, val); + + buf.position(pos + 1); + } + } + + /** + * @param val Value. + */ + public void writeByteArray(byte[] val) { + if (val != null) + lastFinished = writeArray(val, BYTE_ARR_OFF, val.length, val.length); + else + writeInt(-1); + } + + /** + * @param val Value. + */ + public void writeByteArray(byte[] val, int off, int len) { + if (val != null) + lastFinished = writeArray(val, BYTE_ARR_OFF + off, len, len, true); + else + writeInt(-1); + } + + /** + * @param val Value + */ + public void writeShortArray(short[] val) { + if (val != null) + lastFinished = writeArray(val, SHORT_ARR_OFF, val.length, val.length << 1); + else + writeInt(-1); + } + + /** + * @param val Value + */ + public void writeIntArray(int[] val) { + if (val != null) + lastFinished = writeArray(val, INT_ARR_OFF, val.length, val.length << 2); + else + writeInt(-1); + } + + /** + * @param val Value + */ + public void writeLongArray(long[] val) { + if (val != null) + lastFinished = writeArray(val, LONG_ARR_OFF, val.length, val.length << 3); + else + writeInt(-1); + } + + /** + * @param val Value + */ + public void writeFloatArray(float[] val) { + if (val != null) + lastFinished = writeArray(val, FLOAT_ARR_OFF, val.length, val.length << 2); + else + writeInt(-1); + } + + /** + * @param val Value + */ + public void writeDoubleArray(double[] val) { + if (val != null) + lastFinished = writeArray(val, DOUBLE_ARR_OFF, val.length, val.length << 3); + else + writeInt(-1); + } + + /** + * @param val Value + */ + public void writeCharArray(char[] val) { + if (val != null) + lastFinished = writeArray(val, CHAR_ARR_OFF, val.length, val.length << 1); + else + writeInt(-1); + } + + /** + * @param val Value + */ + public void writeBooleanArray(boolean[] val) { + if (val != null) + lastFinished = writeArray(val, BOOLEAN_ARR_OFF, val.length, val.length); + else + writeInt(-1); + } + + /** + * @param val Value + */ + public void writeString(String val) { + writeByteArray(val != null ? val.getBytes() : null); + } + + /** + * @param val Value + */ + public void writeBitSet(BitSet val) { + writeLongArray(val != null ? val.toLongArray() : null); + } + + /** + * @param val Value + */ + public void writeUuid(UUID val) { + writeByteArray(val != null ? U.uuidToBytes(val) : null); + } + + /** + * @param val Value + */ + public void writeIgniteUuid(IgniteUuid val) { + writeByteArray(val != null ? U.igniteUuidToBytes(val) : null); + } + + /** + * @param val Value + */ + public void writeEnum(Enum val) { + writeByte(val != null ? (byte)val.ordinal() : -1); + } + + /** + * @param msg Message. + */ + public void writeMessage(MessageAdapter msg) { + if (msg != null) + lastFinished = buf.hasRemaining() && msg.writeTo(buf); + else + writeByte(Byte.MIN_VALUE); + } + + /** + * @param arr Array. + * @param itemCls Component type. + * @param writer Writer. + */ + public void writeObjectArray(T[] arr, Class itemCls, MessageWriter writer) { + if (arr != null) { + if (it == null) { + writeInt(arr.length); + + if (!lastFinished) + return; + + it = arrayIterator(arr); + } + + Type itemType = type(itemCls); + + while (it.hasNext() || cur != NULL) { + if (cur == NULL) { + cur = it.next(); + + if (cur != null && itemType == Type.MSG) { + cur = ((MessageAdapter)cur).clone(); + + ((MessageAdapter)cur).setWriter(writer); + } + } + + write(itemType, cur); + + if (!lastFinished) + return; + + cur = NULL; + } + + it = null; + } + else + writeInt(-1); + } + + /** + * @param col Collection. + * @param itemCls Item type. + * @param writer Writer. + */ + public void writeCollection(Collection col, Class itemCls, MessageWriter writer) { + if (col != null) { + if (it == null) { + writeInt(col.size()); + + if (!lastFinished) + return; + + it = col.iterator(); + } + + Type itemType = type(itemCls); + + while (it.hasNext() || cur != NULL) { + if (cur == NULL) { + cur = it.next(); + + if (cur != null && itemType == Type.MSG) { + cur = ((MessageAdapter)cur).clone(); + + ((MessageAdapter)cur).setWriter(writer); + } + } + + write(itemType, cur); + + if (!lastFinished) + return; + + cur = NULL; + } + + it = null; + } + else + writeInt(-1); + } + + /** + * @param map Map. + * @param keyCls Key type. + * @param valCls Value type. + * @param writer Writer. + */ + @SuppressWarnings("unchecked") + public void writeMap(Map map, Class keyCls, Class valCls, MessageWriter writer) { + if (map != null) { + if (it == null) { + writeInt(map.size()); + + if (!lastFinished) + return; + + it = map.entrySet().iterator(); + } + + Type keyType = type(keyCls); + Type valType = type(valCls); + + while (it.hasNext() || cur != NULL) { + Map.Entry e; + + if (cur == NULL) { + cur = it.next(); + + e = (Map.Entry)cur; + + if (keyType == Type.MSG || valType == Type.MSG) { + K k = e.getKey(); + V v = e.getValue(); + + if (k != null && keyType == Type.MSG) { + k = (K)((MessageAdapter)k).clone(); + + ((MessageAdapter)k).setWriter(writer); + } + + if (v != null && valType == Type.MSG) { + v = (V)((MessageAdapter)v).clone(); + + ((MessageAdapter)v).setWriter(writer); + } + + cur = e = F.t(k, v); + } + } + else + e = (Map.Entry)cur; + + if (!keyDone) { + write(keyType, e.getKey()); + + if (!lastFinished) + return; + + keyDone = true; + } + + write(valType, e.getValue()); + + if (!lastFinished) + return; + + cur = NULL; + keyDone = false; + } + + it = null; + } + else + writeInt(-1); + } + + /** + * @return Value. + */ + public byte readByte() { + lastFinished = buf.remaining() >= 1; + + if (lastFinished) { + int pos = buf.position(); + + buf.position(pos + 1); + + return UNSAFE.getByte(heapArr, baseOff + pos); + } + else + return 0; + } + + /** + * @return Value. + */ + public short readShort() { + lastFinished = buf.remaining() >= 2; + + if (lastFinished) { + int pos = buf.position(); + + buf.position(pos + 2); + + return UNSAFE.getShort(heapArr, baseOff + pos); + } + else + return 0; + } + + /** + * @return Value. + */ + public int readInt() { + lastFinished = buf.remaining() >= 4; + + if (lastFinished) { + int pos = buf.position(); + + buf.position(pos + 4); + + return UNSAFE.getInt(heapArr, baseOff + pos); + } + else + return 0; + } + + /** + * @return Value. + */ + public long readLong() { + lastFinished = buf.remaining() >= 8; + + if (lastFinished) { + int pos = buf.position(); + + buf.position(pos + 8); + + return UNSAFE.getLong(heapArr, baseOff + pos); + } + else + return 0; + } + + /** + * @return Value. + */ + public float readFloat() { + lastFinished = buf.remaining() >= 4; + + if (lastFinished) { + int pos = buf.position(); + + buf.position(pos + 4); + + return UNSAFE.getFloat(heapArr, baseOff + pos); + } + else + return 0; + } + + /** + * @return Value. + */ + public double readDouble() { + lastFinished = buf.remaining() >= 8; + + if (lastFinished) { + int pos = buf.position(); + + buf.position(pos + 8); + + return UNSAFE.getDouble(heapArr, baseOff + pos); + } + else + return 0; + } + + /** + * @return Value. + */ + public char readChar() { + lastFinished = buf.remaining() >= 2; + + if (lastFinished) { + int pos = buf.position(); + + buf.position(pos + 2); + + return UNSAFE.getChar(heapArr, baseOff + pos); + } + else + return 0; + } + + /** + * @return Value. + */ + public boolean readBoolean() { + lastFinished = buf.hasRemaining(); + + if (lastFinished) { + int pos = buf.position(); + + buf.position(pos + 1); + + return UNSAFE.getBoolean(heapArr, baseOff + pos); + } + else + return false; + } + + /** + * @return Value. + */ + public byte[] readByteArray() { + return readArray(BYTE_ARR_CREATOR, 0, BYTE_ARR_OFF); + } + + /** + * @param len Length. + * @return Value. + */ + public byte[] readByteArray(int len) { + return readArray(BYTE_ARR_CREATOR, 0, BYTE_ARR_OFF, len); + } + + /** + /** + * @return Value. + */ + public short[] readShortArray() { + return readArray(SHORT_ARR_CREATOR, 1, SHORT_ARR_OFF); + } + + /** + * @return Value. + */ + public int[] readIntArray() { + return readArray(INT_ARR_CREATOR, 2, INT_ARR_OFF); + } + + /** + * @return Value. + */ + public long[] readLongArray() { + return readArray(LONG_ARR_CREATOR, 3, LONG_ARR_OFF); + } + + /** + * @return Value. + */ + public float[] readFloatArray() { + return readArray(FLOAT_ARR_CREATOR, 2, FLOAT_ARR_OFF); + } + + /** + * @return Value. + */ + public double[] readDoubleArray() { + return readArray(DOUBLE_ARR_CREATOR, 3, DOUBLE_ARR_OFF); + } + + /** + * @return Value. + */ + public char[] readCharArray() { + return readArray(CHAR_ARR_CREATOR, 1, CHAR_ARR_OFF); + } + + /** + * @return Value. + */ + public boolean[] readBooleanArray() { + return readArray(BOOLEAN_ARR_CREATOR, 0, BOOLEAN_ARR_OFF); + } + + /** + * @return Value. + */ + public String readString() { + byte[] arr = readByteArray(); + + return arr != null ? new String(arr) : null; + } + + /** + * @return Value. + */ + public BitSet readBitSet() { + long[] arr = readLongArray(); + + return arr != null ? BitSet.valueOf(arr) : null; + } + + /** + * @return Value. + */ + public UUID readUuid() { + byte[] arr = readByteArray(); + + return arr != null ? U.bytesToUuid(arr, 0) : null; + } + + /** + * @return Value. + */ + public IgniteUuid readIgniteUuid() { + byte[] arr = readByteArray(); + + return arr != null ? U.bytesToIgniteUuid(arr, 0) : null; + } + + /** + * @param enumCls Enum type. + * @return Value. + */ + @SuppressWarnings("unchecked") + public > T readEnum(Class enumCls) { + byte ord = readByte(); + + return ord >= 0 ? (T)GridEnumCache.get(enumCls)[ord] : null; + } + + /** + * @return Message. + */ + @SuppressWarnings("unchecked") + public T readMessage() { + if (!msgTypeDone) { + if (!buf.hasRemaining()) { + lastFinished = false; + + return null; + } + + byte type = readByte(); + + msg = type == Byte.MIN_VALUE ? null : msgFactory.create(type); + + msgTypeDone = true; + } + + lastFinished = msg == null || msg.readFrom(buf); + + if (lastFinished) { + MessageAdapter msg0 = msg; + + msgTypeDone = false; + msg = null; + + return (T)msg0; + } + else + return null; + } + + /** + * @param itemCls Component type. + * @return Array. + */ + @SuppressWarnings("unchecked") + public T[] readObjectArray(Class itemCls) { + if (readSize == -1) { + int size = readInt(); + + if (!lastFinished) + return null; + + readSize = size; + } + + if (readSize >= 0) { + if (objArr == null) + objArr = (Object[])Array.newInstance(itemCls, readSize); + + Type itemType = type(itemCls); + + for (int i = readItems; i < readSize; i++) { + Object item = read(itemType); + + if (!lastFinished) + return null; + + objArr[i] = item; + + readItems++; + } + } + + readSize = -1; + readItems = 0; + cur = null; + + T[] objArr0 = (T[])objArr; + + objArr = null; + + return objArr0; + } + + /** + * @param itemCls Item type. + * @return Collection. + */ + @SuppressWarnings("unchecked") + public , T> C readCollection(Class itemCls) { + if (readSize == -1) { + int size = readInt(); + + if (!lastFinished) + return null; + + readSize = size; + } + + if (readSize >= 0) { + if (col == null) + col = new ArrayList<>(readSize); + + Type itemType = type(itemCls); + + for (int i = readItems; i < readSize; i++) { + Object item = read(itemType); + + if (!lastFinished) + return null; + + col.add(item); + + readItems++; + } + } + + readSize = -1; + readItems = 0; + cur = null; + + Collection col0 = (Collection)col; + + col = null; + + return (C)col0; + } + + /** + * @param keyCls Key type. + * @param valCls Value type. + * @param linked Whether linked map should be created. + * @return Map. + */ + @SuppressWarnings("unchecked") + public , K, V> M readMap(Class keyCls, Class valCls, boolean linked) { + if (readSize == -1) { + int size = readInt(); + + if (!lastFinished) + return null; + + readSize = size; + } + + if (readSize >= 0) { + if (map == null) + map = linked ? U.newLinkedHashMap(readSize) : U.newHashMap(readSize); + + Type keyType = type(keyCls); + Type valType = type(valCls); + + for (int i = readItems; i < readSize; i++) { + if (!keyDone) { + Object key = read(keyType); + + if (!lastFinished) + return null; + + cur = key; + keyDone = true; + } + + Object val = read(valType); + + if (!lastFinished) + return null; + + map.put(cur, val); + + keyDone = false; + + readItems++; + } + } + + readSize = -1; + readItems = 0; + cur = null; + + Map map0 = (Map)map; + + map = null; + + return (M)map0; + } + + /** + * @param arr Array. + * @param off Offset. + * @param len Length. + * @param bytes Length in bytes. + * @return Whether array was fully written + */ + private boolean writeArray(Object arr, long off, int len, int bytes) { + return writeArray(arr, off, len, bytes, false); + } + + /** + * @param arr Array. + * @param off Offset. + * @param len Length. + * @param bytes Length in bytes. + * @param skipLen {@code true} if length should not be written. + * @return Whether array was fully written + */ + private boolean writeArray(Object arr, long off, int len, int bytes, boolean skipLen) { + assert arr != null; + assert arr.getClass().isArray() && arr.getClass().getComponentType().isPrimitive(); + assert off > 0; + assert len >= 0; + assert bytes >= 0; + assert bytes >= arrOff; + + if (arrOff == -1) { + if (!skipLen) { + if (buf.remaining() < 4) + return false; + + writeInt(len); + } + + arrOff = 0; + } + + int toWrite = bytes - arrOff; + int pos = buf.position(); + int remaining = buf.remaining(); + + if (toWrite <= remaining) { + UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, toWrite); + + pos += toWrite; + + buf.position(pos); + + arrOff = -1; + + return true; + } + else { + UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, remaining); + + pos += remaining; + + buf.position(pos); + + arrOff += remaining; + + return false; + } + } + + /** + * @param creator Array creator. + * @param lenShift Array length shift size. + * @param off Base offset. + * @return Array or special value if it was not fully read. + */ + private T readArray(ArrayCreator creator, int lenShift, long off) { + return readArray(creator, lenShift, off, -1); + } + + /** + * @param creator Array creator. + * @param lenShift Array length shift size. + * @param off Base offset. + * @param len Length. + * @return Array or special value if it was not fully read. + */ + @SuppressWarnings("unchecked") + private T readArray(ArrayCreator creator, int lenShift, long off, int len) { + assert creator != null; + + if (tmpArr == null) { + if (len == -1) { + if (buf.remaining() < 4) { + lastFinished = false; + + return null; + } + + len = readInt(); + } + + switch (len) { + case -1: + lastFinished = true; + + return null; + + case 0: + lastFinished = true; + + return creator.create(0); + + default: + tmpArr = creator.create(len); + tmpArrBytes = len << lenShift; + } + } + + int toRead = tmpArrBytes - tmpArrOff; + int remaining = buf.remaining(); + int pos = buf.position(); + + lastFinished = toRead <= remaining; + + if (lastFinished) { + UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, toRead); + + buf.position(pos + toRead); + + T arr = (T)tmpArr; + + tmpArr = null; + tmpArrBytes = 0; + tmpArrOff = 0; + + return arr; + } + else { + UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, remaining); + + buf.position(pos + remaining); + + tmpArrOff += remaining; + + return null; + } + } + + /** + * @param type Type. + * @param val Value. + */ + private void write(Type type, Object val) { + switch (type) { + case BYTE: + writeByte((Byte)val); + + break; + + case SHORT: + writeShort((Short)val); + + break; + + case INT: + writeInt((Integer)val); + + break; + + case LONG: + writeLong((Long)val); + + break; + + case FLOAT: + writeFloat((Float)val); + + break; + + case DOUBLE: + writeDouble((Double)val); + + break; + + case CHAR: + writeChar((Character)val); + + break; + + case BOOLEAN: + writeBoolean((Boolean)val); + + break; + + case BYTE_ARR: + writeByteArray((byte[])val); + + break; + + case SHORT_ARR: + writeShortArray((short[])val); + + break; + + case INT_ARR: + writeIntArray((int[])val); + + break; + + case LONG_ARR: + writeLongArray((long[])val); + + break; + + case FLOAT_ARR: + writeFloatArray((float[])val); + + break; + + case DOUBLE_ARR: + writeDoubleArray((double[])val); + + break; + + case CHAR_ARR: + writeCharArray((char[])val); + + break; + + case BOOLEAN_ARR: + writeBooleanArray((boolean[])val); + + break; + + case STRING: + writeString((String)val); + + break; + + case BIT_SET: + writeBitSet((BitSet)val); + + break; + + case UUID: + writeUuid((UUID)val); + + break; + + case IGNITE_UUID: + writeIgniteUuid((IgniteUuid)val); + + break; + + case MSG: + writeMessage((MessageAdapter)val); + + break; + + default: + throw new IllegalArgumentException("Unknown type: " + type); + } + } + + /** + * @param type Type. + * @return Value. + */ + private Object read(Type type) { + switch (type) { + case BYTE: + return readByte(); + + case SHORT: + return readShort(); + + case INT: + return readInt(); + + case LONG: + return readLong(); + + case FLOAT: + return readFloat(); + + case DOUBLE: + return readDouble(); + + case CHAR: + return readChar(); + + case BOOLEAN: + return readBoolean(); + + case BYTE_ARR: + return readByteArray(); + + case SHORT_ARR: + return readShortArray(); + + case INT_ARR: + return readIntArray(); + + case LONG_ARR: + return readLongArray(); + + case FLOAT_ARR: + return readFloatArray(); + + case DOUBLE_ARR: + return readDoubleArray(); + + case CHAR_ARR: + return readCharArray(); + + case BOOLEAN_ARR: + return readBooleanArray(); + + case STRING: + return readString(); + + case BIT_SET: + return readBitSet(); + + case UUID: + return readUuid(); + + case IGNITE_UUID: + return readIgniteUuid(); + + case MSG: + return readMessage(); + + default: + throw new IllegalArgumentException("Unknown type: " + type); + } + } + + /** + * @param arr Array. + * @return Array iterator. + */ + private Iterator arrayIterator(final Object[] arr) { + return new Iterator() { + private int idx; + + @Override public boolean hasNext() { + return idx < arr.length; + } + + @Override public Object next() { + if (!hasNext()) + throw new NoSuchElementException(); + + return arr[idx++]; + } + + @Override public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + /** + * Array creator. + */ + private static interface ArrayCreator { + /** + * @param len Array length or {@code -1} if array was not fully read. + * @return New array. + */ + public T create(int len); + } + + /** + */ + private enum Type { + BYTE, + + SHORT, + + INT, + + LONG, + + FLOAT, + + DOUBLE, + + CHAR, + + BOOLEAN, + + BYTE_ARR, + + SHORT_ARR, + + INT_ARR, + + LONG_ARR, + + FLOAT_ARR, + + DOUBLE_ARR, + + CHAR_ARR, + + BOOLEAN_ARR, + + STRING, + + BIT_SET, + + UUID, + + IGNITE_UUID, + + MSG + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java new file mode 100644 index 0000000000000..48c79ce4f08bf --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java @@ -0,0 +1,279 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.direct; + +import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; +import org.jetbrains.annotations.*; + +import java.nio.*; +import java.util.*; + +/** + * Message reader implementation. + */ +public class DirectMessageReader implements MessageReader { + /** Stream. */ + private final DirectByteBufferStream stream; + + /** Whether last field was fully read. */ + private boolean lastRead; + + /** + * @param msgFactory Message factory. + */ + public DirectMessageReader(MessageFactory msgFactory) { + this.stream = new DirectByteBufferStream(msgFactory); + } + + /** {@inheritDoc} */ + @Override public void setBuffer(ByteBuffer buf) { + stream.setBuffer(buf); + } + + /** {@inheritDoc} */ + @Override public byte readByte(String name) { + byte val = stream.readByte(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public short readShort(String name) { + short val = stream.readShort(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public int readInt(String name) { + int val = stream.readInt(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public long readLong(String name) { + long val = stream.readLong(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public float readFloat(String name) { + float val = stream.readFloat(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public double readDouble(String name) { + double val = stream.readDouble(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public char readChar(String name) { + char val = stream.readChar(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public boolean readBoolean(String name) { + boolean val = stream.readBoolean(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Nullable @Override public byte[] readByteArray(String name) { + byte[] arr = stream.readByteArray(); + + lastRead = stream.lastFinished(); + + return arr; + } + + /** {@inheritDoc} */ + @Nullable @Override public short[] readShortArray(String name) { + short[] arr = stream.readShortArray(); + + lastRead = stream.lastFinished(); + + return arr; + } + + /** {@inheritDoc} */ + @Nullable @Override public int[] readIntArray(String name) { + int[] arr = stream.readIntArray(); + + lastRead = stream.lastFinished(); + + return arr; + } + + /** {@inheritDoc} */ + @Nullable @Override public long[] readLongArray(String name) { + long[] arr = stream.readLongArray(); + + lastRead = stream.lastFinished(); + + return arr; + } + + /** {@inheritDoc} */ + @Nullable @Override public float[] readFloatArray(String name) { + float[] arr = stream.readFloatArray(); + + lastRead = stream.lastFinished(); + + return arr; + } + + /** {@inheritDoc} */ + @Nullable @Override public double[] readDoubleArray(String name) { + double[] arr = stream.readDoubleArray(); + + lastRead = stream.lastFinished(); + + return arr; + } + + /** {@inheritDoc} */ + @Nullable @Override public char[] readCharArray(String name) { + char[] arr = stream.readCharArray(); + + lastRead = stream.lastFinished(); + + return arr; + } + + /** {@inheritDoc} */ + @Nullable @Override public boolean[] readBooleanArray(String name) { + boolean[] arr = stream.readBooleanArray(); + + lastRead = stream.lastFinished(); + + return arr; + } + + /** {@inheritDoc} */ + @Override public String readString(String name) { + String val = stream.readString(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public BitSet readBitSet(String name) { + BitSet val = stream.readBitSet(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public UUID readUuid(String name) { + UUID val = stream.readUuid(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public IgniteUuid readIgniteUuid(String name) { + IgniteUuid val = stream.readIgniteUuid(); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Override public > T readEnum(String name, Class enumCls) { + T val = stream.readEnum(enumCls); + + lastRead = stream.lastFinished(); + + return val; + } + + /** {@inheritDoc} */ + @Nullable @Override public T readMessage(String name) { + T msg = stream.readMessage(); + + lastRead = stream.lastFinished(); + + return msg; + } + + /** {@inheritDoc} */ + @Override public T[] readObjectArray(String name, Class itemCls) { + T[] msg = stream.readObjectArray(itemCls); + + lastRead = stream.lastFinished(); + + return msg; + } + + /** {@inheritDoc} */ + @Override public , T> C readCollection(String name, Class itemCls) { + C col = stream.readCollection(itemCls); + + lastRead = stream.lastFinished(); + + return col; + } + + /** {@inheritDoc} */ + @Override public , K, V> M readMap(String name, Class keyCls, Class valCls, + boolean linked) { + M map = stream.readMap(keyCls, valCls, linked); + + lastRead = stream.lastFinished(); + + return map; + } + + /** {@inheritDoc} */ + @Override public boolean isLastRead() { + return lastRead; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java new file mode 100644 index 0000000000000..7526facf7e5a2 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.direct; + +import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; +import org.jetbrains.annotations.*; + +import java.nio.*; +import java.util.*; + +/** + * Message writer implementation. + */ +public class DirectMessageWriter implements MessageWriter { + /** Stream. */ + private final DirectByteBufferStream stream = new DirectByteBufferStream(null); + + /** {@inheritDoc} */ + @Override public void setBuffer(ByteBuffer buf) { + stream.setBuffer(buf); + } + + /** {@inheritDoc} */ + @Override public boolean writeByte(String name, byte val) { + stream.writeByte(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeShort(String name, short val) { + stream.writeShort(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeInt(String name, int val) { + stream.writeInt(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeLong(String name, long val) { + stream.writeLong(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeFloat(String name, float val) { + stream.writeFloat(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeDouble(String name, double val) { + stream.writeDouble(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeChar(String name, char val) { + stream.writeChar(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeBoolean(String name, boolean val) { + stream.writeBoolean(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeByteArray(String name, @Nullable byte[] val) { + stream.writeByteArray(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeShortArray(String name, @Nullable short[] val) { + stream.writeShortArray(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeIntArray(String name, @Nullable int[] val) { + stream.writeIntArray(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeLongArray(String name, @Nullable long[] val) { + stream.writeLongArray(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeFloatArray(String name, @Nullable float[] val) { + stream.writeFloatArray(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeDoubleArray(String name, @Nullable double[] val) { + stream.writeDoubleArray(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeCharArray(String name, @Nullable char[] val) { + stream.writeCharArray(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeBooleanArray(String name, @Nullable boolean[] val) { + stream.writeBooleanArray(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeString(String name, String val) { + stream.writeString(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeBitSet(String name, BitSet val) { + stream.writeBitSet(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeUuid(String name, UUID val) { + stream.writeUuid(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeIgniteUuid(String name, IgniteUuid val) { + stream.writeIgniteUuid(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeEnum(String name, Enum val) { + stream.writeEnum(val); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeMessage(String name, @Nullable MessageAdapter msg) { + if (msg != null) + msg.setWriter(this); + + stream.writeMessage(msg); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeObjectArray(String name, T[] arr, Class itemCls) { + stream.writeObjectArray(arr, itemCls, this); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeCollection(String name, Collection col, Class itemCls) { + stream.writeCollection(col, itemCls, this); + + return stream.lastFinished(); + } + + /** {@inheritDoc} */ + @Override public boolean writeMap(String name, Map map, Class keyCls, Class valCls) { + stream.writeMap(map, keyCls, valCls, this); + + return stream.lastFinished(); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java index 6be401fe1bb90..771b352f4ecfb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java @@ -25,7 +25,6 @@ import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.managers.eventstorage.*; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -38,7 +37,6 @@ import javax.cache.expiry.*; import java.io.*; -import java.nio.*; import java.util.*; import static java.util.Arrays.*; @@ -318,8 +316,8 @@ protected final String stopInfo() { A.notNull(topic, "topic"); try { - if (msg instanceof GridTcpCommunicationMessageAdapter) - ctx.io().send(node, topic, (GridTcpCommunicationMessageAdapter)msg, SYSTEM_POOL); + if (msg instanceof MessageAdapter) + ctx.io().send(node, topic, (MessageAdapter)msg, SYSTEM_POOL); else ctx.io().sendUserMessage(asList(node), msg, topic, false, 0); } @@ -501,24 +499,6 @@ protected final String stopInfo() { return null; } - @Override public boolean writeDelta(UUID nodeId, Object msg, ByteBuffer buf) { - for (MessageCallback patcher : ctx.plugins().extensions(MessageCallback.class)) { - if (!patcher.onSend(nodeId, msg, buf)) - return false; - } - - return true; - } - - @Override public boolean readDelta(UUID nodeId, Class msgCls, ByteBuffer buf) { - for (MessageCallback patcher : ctx.plugins().extensions(MessageCallback.class)) { - if (!patcher.onReceive(nodeId, msgCls, buf)) - return false; - } - - return true; - } - @Override public Collection authenticatedSubjects() { return ctx.grid().security().authenticatedSubjects(); } @@ -547,8 +527,12 @@ protected final String stopInfo() { } } - @Override public GridTcpMessageFactory messageFactory() { - return ctx.messageFactory(); + @Override public MessageFormatter messageFormatter() { + return ctx.io().formatter(); + } + + @Override public MessageFactory messageFactory() { + return ctx.io().messageFactory(); } /** 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 edbc944a78d97..5085a9cdae501 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 @@ -17,9 +17,9 @@ package org.apache.ignite.internal.managers.checkpoint; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -27,7 +27,7 @@ /** * This class defines checkpoint request. */ -public class GridCheckpointRequest extends GridTcpCommunicationMessageAdapter { +public class GridCheckpointRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -85,7 +85,7 @@ public String getCheckpointSpi() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCheckpointRequest _clone = new GridCheckpointRequest(); clone0(_clone); @@ -94,7 +94,7 @@ public String getCheckpointSpi() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridCheckpointRequest _clone = (GridCheckpointRequest)_msg; _clone.sesId = sesId; @@ -105,33 +105,33 @@ public String getCheckpointSpi() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putString(cpSpi)) + if (!writer.writeString("cpSpi", cpSpi)) return false; - commState.idx++; + state++; case 1: - if (!commState.putString(key)) + if (!writer.writeString("key", key)) return false; - commState.idx++; + state++; case 2: - if (!commState.putGridUuid(sesId)) + if (!writer.writeIgniteUuid("sesId", sesId)) return false; - commState.idx++; + state++; } @@ -141,38 +141,32 @@ public String getCheckpointSpi() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - String cpSpi0 = commState.getString(); + cpSpi = reader.readString("cpSpi"); - if (cpSpi0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - cpSpi = cpSpi0; - - commState.idx++; + state++; case 1: - String key0 = commState.getString(); + key = reader.readString("key"); - if (key0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - key = key0; - - commState.idx++; + state++; case 2: - IgniteUuid sesId0 = commState.getGridUuid(); + sesId = reader.readIgniteUuid("sesId"); - if (sesId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - sesId = sesId0; - - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java index ad4d3fe0d1dd5..e53691df3b186 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java @@ -21,18 +21,19 @@ import org.apache.ignite.cluster.*; import org.apache.ignite.events.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.direct.*; import org.apache.ignite.internal.managers.*; import org.apache.ignite.internal.managers.deployment.*; import org.apache.ignite.internal.managers.eventstorage.*; import org.apache.ignite.internal.processors.timeout.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.worker.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.*; import org.jdk8.backport.*; @@ -130,6 +131,12 @@ public class GridIoManager extends GridManagerAdapter 0) { + if (formatterExt.length > 1) + throw new IgniteCheckedException("More than one MessageFormatter extension is defined. Check your " + + "plugins configuration and make sure that only one of them provides custom message format."); + + formatter = formatterExt[0]; + } + else { + formatter = new MessageFormatter() { + @Override public MessageWriter writer() { + return new DirectMessageWriter(); + } + + @Override public MessageReader reader() { + return new DirectMessageReader(msgFactory); + } + }; + } + + msgFactory = new GridIoMessageFactory(formatter, ctx.plugins().extensions(MessageFactory.class)); + if (log.isDebugEnabled()) log.debug(startInfo()); } @@ -841,7 +889,7 @@ private void send( ClusterNode node, Object topic, int topicOrd, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, GridIoPolicy plc, boolean ordered, long timeout, @@ -852,8 +900,6 @@ private void send( assert msg != null; assert plc != null; - GridIoMessage ioMsg = new GridIoMessage(plc, topic, topicOrd, msg, ordered, timeout, skipOnTimeout); - if (locNodeId.equals(node.id())) { assert plc != P2P_POOL; @@ -862,12 +908,16 @@ private void send( if (commLsnr == null) throw new IgniteCheckedException("Trying to send message when grid is not fully started."); + GridIoMessage ioMsg = new GridIoMessage(plc, topic, topicOrd, msg, ordered, timeout, skipOnTimeout); + if (ordered) processOrderedMessage(locNodeId, ioMsg, plc, null); else processRegularMessage0(ioMsg, locNodeId); } else { + GridIoMessage ioMsg = new GridIoMessage(plc, topic, topicOrd, msg.clone(), ordered, timeout, skipOnTimeout); + if (topicOrd < 0) ioMsg.topicBytes(marsh.marshal(topic)); @@ -890,7 +940,7 @@ private void send( * @param plc Type of processing. * @throws IgniteCheckedException Thrown in case of any errors. */ - public void send(UUID nodeId, Object topic, GridTcpCommunicationMessageAdapter msg, GridIoPolicy plc) + public void send(UUID nodeId, Object topic, MessageAdapter msg, GridIoPolicy plc) throws IgniteCheckedException { ClusterNode node = ctx.discovery().node(nodeId); @@ -908,7 +958,7 @@ public void send(UUID nodeId, Object topic, GridTcpCommunicationMessageAdapter m * @throws IgniteCheckedException Thrown in case of any errors. */ @SuppressWarnings("TypeMayBeWeakened") - public void send(UUID nodeId, GridTopic topic, GridTcpCommunicationMessageAdapter msg, GridIoPolicy plc) + public void send(UUID nodeId, GridTopic topic, MessageAdapter msg, GridIoPolicy plc) throws IgniteCheckedException { ClusterNode node = ctx.discovery().node(nodeId); @@ -925,7 +975,7 @@ public void send(UUID nodeId, GridTopic topic, GridTcpCommunicationMessageAdapte * @param plc Type of processing. * @throws IgniteCheckedException Thrown in case of any errors. */ - public void send(ClusterNode node, Object topic, GridTcpCommunicationMessageAdapter msg, GridIoPolicy plc) + public void send(ClusterNode node, Object topic, MessageAdapter msg, GridIoPolicy plc) throws IgniteCheckedException { send(node, topic, -1, msg, plc, false, 0, false); } @@ -937,7 +987,7 @@ public void send(ClusterNode node, Object topic, GridTcpCommunicationMessageAdap * @param plc Type of processing. * @throws IgniteCheckedException Thrown in case of any errors. */ - public void send(ClusterNode node, GridTopic topic, GridTcpCommunicationMessageAdapter msg, GridIoPolicy plc) + public void send(ClusterNode node, GridTopic topic, MessageAdapter msg, GridIoPolicy plc) throws IgniteCheckedException { send(node, topic, topic.ordinal(), msg, plc, false, 0, false); } @@ -954,7 +1004,7 @@ public void send(ClusterNode node, GridTopic topic, GridTcpCommunicationMessageA public void sendOrderedMessage( ClusterNode node, Object topic, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, GridIoPolicy plc, long timeout, boolean skipOnTimeout @@ -976,7 +1026,7 @@ public void sendOrderedMessage( public void sendOrderedMessage( UUID nodeId, Object topic, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, GridIoPolicy plc, long timeout, boolean skipOnTimeout @@ -1003,7 +1053,7 @@ public void sendOrderedMessage( public void sendOrderedMessage( Collection nodes, Object topic, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, GridIoPolicy plc, long timeout, boolean skipOnTimeout @@ -1024,7 +1074,7 @@ public void sendOrderedMessage( public void send( Collection nodes, Object topic, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, GridIoPolicy plc ) throws IgniteCheckedException { send(nodes, topic, -1, msg, plc, false, 0, false); @@ -1040,7 +1090,7 @@ public void send( public void send( Collection nodes, GridTopic topic, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, GridIoPolicy plc ) throws IgniteCheckedException { send(nodes, topic, topic.ordinal(), msg, plc, false, 0, false); @@ -1100,7 +1150,7 @@ public void sendUserMessage(Collection nodes, Object msg, depClsName = cls0.getName(); } - GridTcpCommunicationMessageAdapter ioMsg = new GridIoUserMessage( + MessageAdapter ioMsg = new GridIoUserMessage( msg, serMsg, depClsName, @@ -1173,7 +1223,7 @@ private void send( Collection nodes, Object topic, int topicOrd, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, GridIoPolicy plc, boolean ordered, long timeout, @@ -1192,15 +1242,8 @@ private void send( // Small optimization, as communication SPIs may have lighter implementation for sending // messages to one node vs. many. if (!nodes.isEmpty()) { - boolean first = true; - - for (ClusterNode node : nodes) { - GridTcpCommunicationMessageAdapter msg0 = first ? msg : msg.clone(); - - first = false; - - send(node, topic, topicOrd, msg0, plc, ordered, timeout, skipOnTimeout); - } + for (ClusterNode node : nodes) + send(node, topic, topicOrd, msg, plc, ordered, timeout, skipOnTimeout); } else if (log.isDebugEnabled()) log.debug("Failed to send message to empty nodes collection [topic=" + topic + ", msg=" + 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 67766a1db7d38..c77f1745f7b97 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 @@ -18,9 +18,9 @@ package org.apache.ignite.internal.managers.communication; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -28,7 +28,7 @@ /** * Wrapper for all grid messages. */ -public class GridIoMessage extends GridTcpCommunicationMessageAdapter { +public class GridIoMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -56,7 +56,7 @@ public class GridIoMessage extends GridTcpCommunicationMessageAdapter { private boolean skipOnTimeout; /** Message. */ - private GridTcpCommunicationMessageAdapter msg; + private MessageAdapter msg; /** * No-op constructor to support {@link Externalizable} interface. @@ -79,7 +79,7 @@ public GridIoMessage( GridIoPolicy plc, Object topic, int topicOrd, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, boolean ordered, long timeout, boolean skipOnTimeout @@ -180,7 +180,7 @@ boolean isOrdered() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridIoMessage _clone = new GridIoMessage(); clone0(_clone); @@ -190,7 +190,7 @@ boolean isOrdered() { /** {@inheritDoc} */ @SuppressWarnings("RedundantCast") - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridIoMessage _clone = (GridIoMessage)_msg; _clone.plc = plc; @@ -200,63 +200,63 @@ boolean isOrdered() { _clone.ordered = ordered; _clone.timeout = timeout; _clone.skipOnTimeout = skipOnTimeout; - _clone.msg = msg != null ? (GridTcpCommunicationMessageAdapter)msg.clone() : null; + _clone.msg = msg != null ? (MessageAdapter)msg.clone() : null; } /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putMessage(msg)) + if (!writer.writeMessage("msg", msg)) return false; - commState.idx++; + state++; case 1: - if (!commState.putBoolean(ordered)) + if (!writer.writeBoolean("ordered", ordered)) return false; - commState.idx++; + state++; case 2: - if (!commState.putEnum(plc)) + if (!writer.writeEnum("plc", plc)) return false; - commState.idx++; + state++; case 3: - if (!commState.putBoolean(skipOnTimeout)) + if (!writer.writeBoolean("skipOnTimeout", skipOnTimeout)) return false; - commState.idx++; + state++; case 4: - if (!commState.putLong(timeout)) + if (!writer.writeLong("timeout", timeout)) return false; - commState.idx++; + state++; case 5: - if (!commState.putByteArray(topicBytes)) + if (!writer.writeByteArray("topicBytes", topicBytes)) return false; - commState.idx++; + state++; case 6: - if (!commState.putInt(topicOrd)) + if (!writer.writeInt("topicOrd", topicOrd)) return false; - commState.idx++; + state++; } @@ -266,70 +266,64 @@ boolean isOrdered() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - Object msg0 = commState.getMessage(); + msg = reader.readMessage("msg"); - if (msg0 == MSG_NOT_READ) + if (!reader.isLastRead()) return false; - msg = (GridTcpCommunicationMessageAdapter)msg0; - - commState.idx++; + state++; case 1: - if (buf.remaining() < 1) - return false; + ordered = reader.readBoolean("ordered"); - ordered = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - if (buf.remaining() < 1) - return false; + plc = reader.readEnum("plc", GridIoPolicy.class); - byte plc0 = commState.getByte(); - - plc = GridIoPolicy.fromOrdinal(plc0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - if (buf.remaining() < 1) - return false; + skipOnTimeout = reader.readBoolean("skipOnTimeout"); - skipOnTimeout = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (buf.remaining() < 8) - return false; + timeout = reader.readLong("timeout"); - timeout = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - byte[] topicBytes0 = commState.getByteArray(); + topicBytes = reader.readByteArray("topicBytes"); - if (topicBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - topicBytes = topicBytes0; - - commState.idx++; + state++; case 6: - if (buf.remaining() < 4) - return false; + topicOrd = reader.readInt("topicOrd"); - topicOrd = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java new file mode 100644 index 0000000000000..e8481f1688ca9 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java @@ -0,0 +1,543 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.managers.communication; + +import org.apache.ignite.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.managers.checkpoint.*; +import org.apache.ignite.internal.managers.deployment.*; +import org.apache.ignite.internal.managers.eventstorage.*; +import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.processors.cache.distributed.*; +import org.apache.ignite.internal.processors.cache.distributed.dht.*; +import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*; +import org.apache.ignite.internal.processors.cache.distributed.near.*; +import org.apache.ignite.internal.processors.cache.query.*; +import org.apache.ignite.internal.processors.cache.version.*; +import org.apache.ignite.internal.processors.clock.*; +import org.apache.ignite.internal.processors.continuous.*; +import org.apache.ignite.internal.processors.dataload.*; +import org.apache.ignite.internal.processors.fs.*; +import org.apache.ignite.internal.processors.rest.handlers.task.*; +import org.apache.ignite.internal.processors.streamer.*; +import org.apache.ignite.internal.util.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; +import org.apache.ignite.spi.collision.jobstealing.*; +import org.apache.ignite.spi.communication.tcp.*; +import org.jdk8.backport.*; + +import java.util.*; + +/** + * Message factory implementation. + */ +public class GridIoMessageFactory implements MessageFactory { + /** Custom messages registry. Used for test purposes. */ + private static final Map> CUSTOM = new ConcurrentHashMap8<>(); + + /** Message reader factory. */ + private final MessageFormatter formatter; + + /** Extensions. */ + private final MessageFactory[] ext; + + /** + * @param formatter Message formatter. + * @param ext Extensions. + */ + public GridIoMessageFactory(MessageFormatter formatter, MessageFactory[] ext) { + assert formatter != null; + + this.formatter = formatter; + this.ext = ext; + } + + /** {@inheritDoc} */ + @Override public MessageAdapter create(byte type) { + MessageAdapter msg = null; + + switch (type) { + case TcpCommunicationSpi.NODE_ID_MSG_TYPE: + return new TcpCommunicationSpi.NodeIdMessage(); + + case TcpCommunicationSpi.RECOVERY_LAST_ID_MSG_TYPE: + return new TcpCommunicationSpi.RecoveryLastReceivedMessage(); + + case TcpCommunicationSpi.HANDSHAKE_MSG_TYPE: + return new TcpCommunicationSpi.HandshakeMessage(); + + case 0: + msg = new GridJobCancelRequest(); + + break; + + case 1: + msg = new GridJobExecuteRequest(); + + break; + + case 2: + msg = new GridJobExecuteResponse(); + + break; + + case 3: + msg = new GridJobSiblingsRequest(); + + break; + + case 4: + msg = new GridJobSiblingsResponse(); + + break; + + case 5: + msg = new GridTaskCancelRequest(); + + break; + + case 6: + msg = new GridTaskSessionRequest(); + + break; + + case 7: + msg = new GridCheckpointRequest(); + + break; + + case 8: + msg = new GridIoMessage(); + + break; + + case 9: + msg = new GridIoUserMessage(); + + break; + + case 10: + msg = new GridDeploymentInfoBean(); + + break; + + case 11: + msg = new GridDeploymentRequest(); + + break; + + case 12: + msg = new GridDeploymentResponse(); + + break; + + case 13: + msg = new GridEventStorageMessage(); + + break; + + case 14: + msg = new GridCacheEvictionRequest(); + + break; + + case 15: + msg = new GridCacheEvictionResponse(); + + break; + + case 16: + msg = new GridCacheOptimisticCheckPreparedTxRequest(); + + break; + + case 17: + msg = new GridCacheOptimisticCheckPreparedTxResponse(); + + break; + + case 18: + msg = new GridCachePessimisticCheckCommittedTxRequest(); + + break; + + case 19: + msg = new GridCachePessimisticCheckCommittedTxResponse(); + + break; + + case 20: + msg = new GridCacheTtlUpdateRequest(); + + break; + + case 21: + msg = new GridDistributedLockRequest(); + + break; + + case 22: + msg = new GridDistributedLockResponse(); + + break; + + case 23: + msg = new GridDistributedTxFinishRequest(); + + break; + + case 24: + msg = new GridDistributedTxFinishResponse(); + + break; + + case 25: + msg = new GridDistributedTxPrepareRequest(); + + break; + + case 26: + msg = new GridDistributedTxPrepareResponse(); + + break; + + case 27: + msg = new GridDistributedUnlockRequest(); + + break; + + case 28: + msg = new GridDhtAffinityAssignmentRequest(); + + break; + + case 29: + msg = new GridDhtAffinityAssignmentResponse(); + + break; + + case 30: + msg = new GridDhtLockRequest(); + + break; + + case 31: + msg = new GridDhtLockResponse(); + + break; + + case 32: + msg = new GridDhtTxFinishRequest(); + + break; + + case 33: + msg = new GridDhtTxFinishResponse(); + + break; + + case 34: + msg = new GridDhtTxPrepareRequest(); + + break; + + case 35: + msg = new GridDhtTxPrepareResponse(); + + break; + + case 36: + msg = new GridDhtUnlockRequest(); + + break; + + case 37: + msg = new GridDhtAtomicDeferredUpdateResponse(); + + break; + + case 38: + msg = new GridDhtAtomicUpdateRequest(); + + break; + + case 39: + msg = new GridDhtAtomicUpdateResponse(); + + break; + + case 40: + msg = new GridNearAtomicUpdateRequest(); + + break; + + case 41: + msg = new GridNearAtomicUpdateResponse(); + + break; + + case 42: + msg = new GridDhtForceKeysRequest(); + + break; + + case 43: + msg = new GridDhtForceKeysResponse(); + + break; + + case 44: + msg = new GridDhtPartitionDemandMessage(); + + break; + + case 45: + msg = new GridDhtPartitionSupplyMessage(); + + break; + + case 46: + msg = new GridDhtPartitionsFullMessage(); + + break; + + case 47: + msg = new GridDhtPartitionsSingleMessage(); + + break; + + case 48: + msg = new GridDhtPartitionsSingleRequest(); + + break; + + case 49: + msg = new GridNearGetRequest(); + + break; + + case 50: + msg = new GridNearGetResponse(); + + break; + + case 51: + msg = new GridNearLockRequest(); + + break; + + case 52: + msg = new GridNearLockResponse(); + + break; + + case 53: + msg = new GridNearTxFinishRequest(); + + break; + + case 54: + msg = new GridNearTxFinishResponse(); + + break; + + case 55: + msg = new GridNearTxPrepareRequest(); + + break; + + case 56: + msg = new GridNearTxPrepareResponse(); + + break; + + case 57: + msg = new GridNearUnlockRequest(); + + break; + + case 58: + msg = new GridCacheQueryRequest(); + + break; + + case 59: + msg = new GridCacheQueryResponse(); + + break; + + case 60: + msg = new GridClockDeltaSnapshotMessage(); + + break; + + case 61: + msg = new GridContinuousMessage(); + + break; + + case 62: + msg = new GridDataLoadRequest(); + + break; + + case 63: + msg = new GridDataLoadResponse(); + + break; + + case 64: + msg = new GridGgfsAckMessage(); + + break; + + case 65: + msg = new GridGgfsBlockKey(); + + break; + + case 66: + msg = new GridGgfsBlocksMessage(); + + break; + + case 67: + msg = new GridGgfsDeleteMessage(); + + break; + + case 68: + msg = new GridGgfsFileAffinityRange(); + + break; + + case 69: + msg = new GridGgfsFragmentizerRequest(); + + break; + + case 70: + msg = new GridGgfsFragmentizerResponse(); + + break; + + case 71: + msg = new GridGgfsSyncMessage(); + + break; + + case 76: + msg = new GridTaskResultRequest(); + + break; + + case 77: + msg = new GridTaskResultResponse(); + + break; + + case 79: + msg = new GridStreamerCancelRequest(); + + break; + + case 80: + msg = new GridStreamerExecutionRequest(); + + break; + + case 81: + msg = new GridStreamerResponse(); + + break; + + case 82: + msg = new JobStealingRequest(); + + break; + + case 83: + msg = new GridClockDeltaVersion(); + + break; + + case 84: + msg = new GridByteArrayList(); + + break; + + case 85: + msg = new GridLongList(); + + break; + + case 86: + msg = new GridCacheVersion(); + + break; + + case 87: + msg = new GridDhtPartitionExchangeId(); + + break; + + case 88: + msg = new GridCacheValueBytes(); + + break; + + default: + if (ext != null) { + for (MessageFactory factory : ext) { + msg = factory.create(type); + + if (msg != null) + break; + } + } + + if (msg == null) { + IgniteOutClosure c = CUSTOM.get(type); + + if (c != null) + msg = c.apply(); + } + } + + if (msg == null) + throw new IgniteException("Invalid message type: " + type); + + msg.setReader(formatter.reader()); + + return msg; + } + + /** + * Registers factory for custom message. Used for test purposes. + * + * @param type Message type. + * @param c Message producer. + */ + public static void registerCustom(byte type, IgniteOutClosure c) { + assert c != null; + + CUSTOM.put(type, c); + } +} 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 481456d76ffbf..05ff2dfa2ff5a 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 @@ -20,10 +20,10 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.managers.deployment.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -33,7 +33,7 @@ /** * User message wrapper. */ -public class GridIoUserMessage extends GridTcpCommunicationMessageAdapter { +public class GridIoUserMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -204,7 +204,7 @@ public void deployment(GridDeployment dep) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridIoUserMessage _clone = new GridIoUserMessage(); clone0(_clone); @@ -213,7 +213,7 @@ public void deployment(GridDeployment dep) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridIoUserMessage _clone = (GridIoUserMessage)_msg; _clone.body = body; @@ -231,89 +231,57 @@ public void deployment(GridDeployment dep) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(bodyBytes)) + if (!writer.writeByteArray("bodyBytes", bodyBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(clsLdrId)) + if (!writer.writeIgniteUuid("clsLdrId", clsLdrId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putString(depClsName)) + if (!writer.writeString("depClsName", depClsName)) return false; - commState.idx++; + state++; case 3: - if (!commState.putEnum(depMode)) + if (!writer.writeEnum("depMode", depMode)) return false; - commState.idx++; + state++; case 4: - if (ldrParties != null) { - if (commState.it == null) { - if (!commState.putInt(ldrParties.size())) - return false; - - commState.it = ldrParties.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putUuid(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putGridUuid(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("ldrParties", ldrParties, UUID.class, IgniteUuid.class)) + return false; - commState.idx++; + state++; case 5: - if (!commState.putByteArray(topicBytes)) + if (!writer.writeByteArray("topicBytes", topicBytes)) return false; - commState.idx++; + state++; case 6: - if (!commState.putString(userVer)) + if (!writer.writeString("userVer", userVer)) return false; - commState.idx++; + state++; } @@ -323,110 +291,64 @@ public void deployment(GridDeployment dep) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - byte[] bodyBytes0 = commState.getByteArray(); + bodyBytes = reader.readByteArray("bodyBytes"); - if (bodyBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - bodyBytes = bodyBytes0; - - commState.idx++; + state++; case 1: - IgniteUuid clsLdrId0 = commState.getGridUuid(); + clsLdrId = reader.readIgniteUuid("clsLdrId"); - if (clsLdrId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - clsLdrId = clsLdrId0; - - commState.idx++; + state++; case 2: - String depClsName0 = commState.getString(); + depClsName = reader.readString("depClsName"); - if (depClsName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - depClsName = depClsName0; - - commState.idx++; + state++; case 3: - if (buf.remaining() < 1) - return false; - - byte depMode0 = commState.getByte(); + depMode = reader.readEnum("depMode", DeploymentMode.class); - depMode = DeploymentMode.fromOrdinal(depMode0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (ldrParties == null) - ldrParties = U.newHashMap(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } - - IgniteUuid _val = commState.getGridUuid(); + ldrParties = reader.readMap("ldrParties", UUID.class, IgniteUuid.class, false); - if (_val == GRID_UUID_NOT_READ) - return false; - - ldrParties.put((UUID)commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - byte[] topicBytes0 = commState.getByteArray(); + topicBytes = reader.readByteArray("topicBytes"); - if (topicBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - topicBytes = topicBytes0; - - commState.idx++; + state++; case 6: - String userVer0 = commState.getString(); + userVer = reader.readString("userVer"); - if (userVer0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - userVer = userVer0; - - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java index aa1b288b3424a..d9a7d9bdb71a7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java @@ -24,13 +24,13 @@ import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.managers.eventstorage.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.util.*; @@ -282,7 +282,7 @@ private void processResourceRequest(UUID nodeId, GridDeploymentRequest req) { * @param topic Response topic. * @param res Response. */ - private void sendResponse(UUID nodeId, Object topic, GridTcpCommunicationMessageAdapter res) { + private void sendResponse(UUID nodeId, Object topic, MessageAdapter res) { ClusterNode node = ctx.discovery().node(nodeId); if (node != null) { @@ -314,7 +314,7 @@ else if (log.isDebugEnabled()) void sendUndeployRequest(String rsrcName, Collection rmtNodes) throws IgniteCheckedException { assert !rmtNodes.contains(ctx.discovery().localNode()); - GridTcpCommunicationMessageAdapter req = new GridDeploymentRequest(null, null, rsrcName, true); + MessageAdapter req = new GridDeploymentRequest(null, null, rsrcName, true); if (!rmtNodes.isEmpty()) { ctx.io().send( 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 e93c3c972a9e7..a84d0493a4358 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 @@ -19,10 +19,10 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -31,7 +31,7 @@ /** * Deployment info bean. */ -public class GridDeploymentInfoBean extends GridTcpCommunicationMessageAdapter implements GridDeploymentInfo, +public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploymentInfo, Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -139,7 +139,7 @@ public void localDeploymentOwner(boolean locDepOwner) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDeploymentInfoBean _clone = new GridDeploymentInfoBean(); clone0(_clone); @@ -148,7 +148,7 @@ public void localDeploymentOwner(boolean locDepOwner) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridDeploymentInfoBean _clone = (GridDeploymentInfoBean)_msg; _clone.clsLdrId = clsLdrId; @@ -161,77 +161,45 @@ public void localDeploymentOwner(boolean locDepOwner) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(clsLdrId)) + if (!writer.writeIgniteUuid("clsLdrId", clsLdrId)) return false; - commState.idx++; + state++; case 1: - if (!commState.putEnum(depMode)) + if (!writer.writeEnum("depMode", depMode)) return false; - commState.idx++; + state++; case 2: - if (!commState.putBoolean(locDepOwner)) + if (!writer.writeBoolean("locDepOwner", locDepOwner)) return false; - commState.idx++; + state++; case 3: - if (participants != null) { - if (commState.it == null) { - if (!commState.putInt(participants.size())) - return false; - - commState.it = participants.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putUuid(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putGridUuid(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("participants", participants, UUID.class, IgniteUuid.class)) + return false; - commState.idx++; + state++; case 4: - if (!commState.putString(userVer)) + if (!writer.writeString("userVer", userVer)) return false; - commState.idx++; + state++; } @@ -241,88 +209,48 @@ public void localDeploymentOwner(boolean locDepOwner) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid clsLdrId0 = commState.getGridUuid(); + clsLdrId = reader.readIgniteUuid("clsLdrId"); - if (clsLdrId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - clsLdrId = clsLdrId0; - - commState.idx++; + state++; case 1: - if (buf.remaining() < 1) - return false; - - byte depMode0 = commState.getByte(); + depMode = reader.readEnum("depMode", DeploymentMode.class); - depMode = DeploymentMode.fromOrdinal(depMode0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - if (buf.remaining() < 1) - return false; + locDepOwner = reader.readBoolean("locDepOwner"); - locDepOwner = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (participants == null) - participants = U.newHashMap(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } + participants = reader.readMap("participants", UUID.class, IgniteUuid.class, false); - IgniteUuid _val = commState.getGridUuid(); - - if (_val == GRID_UUID_NOT_READ) - return false; - - participants.put((UUID)commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - String userVer0 = commState.getString(); + userVer = reader.readString("userVer"); - if (userVer0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - userVer = userVer0; - - commState.idx++; + state++; } 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 aa35a7e897733..50d9b24fd62ff 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 @@ -18,10 +18,10 @@ package org.apache.ignite.internal.managers.deployment; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -30,7 +30,7 @@ /** * Deployment request. */ -public class GridDeploymentRequest extends GridTcpCommunicationMessageAdapter { +public class GridDeploymentRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -157,7 +157,7 @@ public void nodeIds(Collection nodeIds) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDeploymentRequest _clone = new GridDeploymentRequest(); clone0(_clone); @@ -166,7 +166,7 @@ public void nodeIds(Collection nodeIds) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridDeploymentRequest _clone = (GridDeploymentRequest)_msg; _clone.resTopic = resTopic; @@ -180,66 +180,45 @@ public void nodeIds(Collection nodeIds) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putBoolean(isUndeploy)) + if (!writer.writeBoolean("isUndeploy", isUndeploy)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(ldrId)) + if (!writer.writeIgniteUuid("ldrId", ldrId)) return false; - commState.idx++; + state++; case 2: - if (nodeIds != null) { - if (commState.it == null) { - if (!commState.putInt(nodeIds.size())) - return false; - - commState.it = nodeIds.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putUuid((UUID)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nodeIds", nodeIds, UUID.class)) + return false; - commState.idx++; + state++; case 3: - if (!commState.putByteArray(resTopicBytes)) + if (!writer.writeByteArray("resTopicBytes", resTopicBytes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putString(rsrcName)) + if (!writer.writeString("rsrcName", rsrcName)) return false; - commState.idx++; + state++; } @@ -249,75 +228,48 @@ public void nodeIds(Collection nodeIds) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - if (buf.remaining() < 1) - return false; + isUndeploy = reader.readBoolean("isUndeploy"); - isUndeploy = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 1: - IgniteUuid ldrId0 = commState.getGridUuid(); + ldrId = reader.readIgniteUuid("ldrId"); - if (ldrId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - ldrId = ldrId0; - - commState.idx++; + state++; case 2: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; + nodeIds = reader.readCollection("nodeIds", UUID.class); - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nodeIds == null) - nodeIds = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - nodeIds.add((UUID)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - byte[] resTopicBytes0 = commState.getByteArray(); + resTopicBytes = reader.readByteArray("resTopicBytes"); - if (resTopicBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - resTopicBytes = resTopicBytes0; - - commState.idx++; + state++; case 4: - String rsrcName0 = commState.getString(); + rsrcName = reader.readString("rsrcName"); - if (rsrcName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - rsrcName = rsrcName0; - - commState.idx++; + state++; } 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 24bd8e0a22c67..9c54b844d5a65 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 @@ -18,8 +18,8 @@ package org.apache.ignite.internal.managers.deployment; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -27,7 +27,7 @@ /** * Grid deployment response containing requested resource bytes. */ -public class GridDeploymentResponse extends GridTcpCommunicationMessageAdapter { +public class GridDeploymentResponse extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -107,7 +107,7 @@ void errorMessage(String errMsg) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDeploymentResponse _clone = new GridDeploymentResponse(); clone0(_clone); @@ -116,44 +116,44 @@ void errorMessage(String errMsg) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridDeploymentResponse _clone = (GridDeploymentResponse)_msg; _clone.success = success; _clone.errMsg = errMsg; - _clone.byteSrc = byteSrc; + _clone.byteSrc = byteSrc != null ? (GridByteArrayList)byteSrc.clone() : null; } /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArrayList(byteSrc)) + if (!writer.writeMessage("byteSrc", byteSrc)) return false; - commState.idx++; + state++; case 1: - if (!commState.putString(errMsg)) + if (!writer.writeString("errMsg", errMsg)) return false; - commState.idx++; + state++; case 2: - if (!commState.putBoolean(success)) + if (!writer.writeBoolean("success", success)) return false; - commState.idx++; + state++; } @@ -163,36 +163,32 @@ void errorMessage(String errMsg) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - GridByteArrayList byteSrc0 = commState.getByteArrayList(); + byteSrc = reader.readMessage("byteSrc"); - if (byteSrc0 == BYTE_ARR_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - byteSrc = byteSrc0; - - commState.idx++; + state++; case 1: - String errMsg0 = commState.getString(); + errMsg = reader.readString("errMsg"); - if (errMsg0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - errMsg = errMsg0; - - commState.idx++; + state++; case 2: - if (buf.remaining() < 1) - return false; + success = reader.readBoolean("success"); - success = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java index 834e6498fe320..39df697ce83f0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java @@ -34,7 +34,6 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.worker.*; import org.apache.ignite.lang.*; -import org.apache.ignite.plugin.extensions.discovery.*; import org.apache.ignite.plugin.security.*; import org.apache.ignite.plugin.segmentation.*; import org.apache.ignite.spi.*; @@ -266,11 +265,6 @@ public void setNodeAttributes(Map attrs, IgniteProductVersion ve c.updateAlives(node); } - if (type == EVT_NODE_JOINED) { - for (DiscoveryCallback listener : ctx.plugins().extensions(DiscoveryCallback.class)) - listener.beforeNodeJoined(node); - } - // Put topology snapshot into discovery history. // There is no race possible between history maintenance and concurrent discovery // event notifications, since SPI notifies manager about all events from this listener. @@ -369,11 +363,6 @@ public void setNodeAttributes(Map attrs, IgniteProductVersion ve topVer.setIfGreater(locNode.order()); - for (DiscoveryCallback listener : ctx.plugins().extensions(DiscoveryCallback.class)) { - listener.onStart(discoCache().remoteNodes()); - listener.onStart(discoCache().daemonNodes()); - } - // Start discovery worker. new IgniteThread(discoWrk).start(); @@ -1416,9 +1405,6 @@ else if (log.isDebugEnabled()) if (hasRslvrs) segChkWrk.scheduleSegmentCheck(); - for (DiscoveryCallback listener : ctx.plugins().extensions(DiscoveryCallback.class)) - listener.onNodeLeft(node); - if (!isDaemon) { if (!isLocDaemon) { if (log.isInfoEnabled()) @@ -1440,9 +1426,6 @@ else if (log.isDebugEnabled()) if (hasRslvrs) segChkWrk.scheduleSegmentCheck(); - for (DiscoveryCallback listener : ctx.plugins().extensions(DiscoveryCallback.class)) - listener.onNodeLeft(node); - if (!isDaemon) { if (!isLocDaemon) { U.warn(log, "Node FAILED: " + node); 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 37d1f19882edb..058ac8ee6d31a 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 @@ -20,10 +20,10 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.events.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.nio.*; @@ -32,7 +32,7 @@ /** * Event storage message. */ -public class GridEventStorageMessage extends GridTcpCommunicationMessageAdapter { +public class GridEventStorageMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -262,7 +262,7 @@ void exceptionBytes(byte[] exBytes) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridEventStorageMessage _clone = new GridEventStorageMessage(); clone0(_clone); @@ -271,7 +271,7 @@ void exceptionBytes(byte[] exBytes) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridEventStorageMessage _clone = (GridEventStorageMessage)_msg; _clone.resTopic = resTopic; @@ -291,101 +291,69 @@ void exceptionBytes(byte[] exBytes) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(clsLdrId)) + if (!writer.writeIgniteUuid("clsLdrId", clsLdrId)) return false; - commState.idx++; + state++; case 1: - if (!commState.putEnum(depMode)) + if (!writer.writeEnum("depMode", depMode)) return false; - commState.idx++; + state++; case 2: - if (!commState.putByteArray(evtsBytes)) + if (!writer.writeByteArray("evtsBytes", evtsBytes)) return false; - commState.idx++; + state++; case 3: - if (!commState.putByteArray(exBytes)) + if (!writer.writeByteArray("exBytes", exBytes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(filter)) + if (!writer.writeByteArray("filter", filter)) return false; - commState.idx++; + state++; case 5: - if (!commState.putString(filterClsName)) + if (!writer.writeString("filterClsName", filterClsName)) return false; - commState.idx++; + state++; case 6: - if (ldrParties != null) { - if (commState.it == null) { - if (!commState.putInt(ldrParties.size())) - return false; - - commState.it = ldrParties.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putUuid(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putGridUuid(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("ldrParties", ldrParties, UUID.class, IgniteUuid.class)) + return false; - commState.idx++; + state++; case 7: - if (!commState.putByteArray(resTopicBytes)) + if (!writer.writeByteArray("resTopicBytes", resTopicBytes)) return false; - commState.idx++; + state++; case 8: - if (!commState.putString(userVer)) + if (!writer.writeString("userVer", userVer)) return false; - commState.idx++; + state++; } @@ -395,130 +363,80 @@ void exceptionBytes(byte[] exBytes) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid clsLdrId0 = commState.getGridUuid(); + clsLdrId = reader.readIgniteUuid("clsLdrId"); - if (clsLdrId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - clsLdrId = clsLdrId0; - - commState.idx++; + state++; case 1: - if (buf.remaining() < 1) - return false; + depMode = reader.readEnum("depMode", DeploymentMode.class); - byte depMode0 = commState.getByte(); - - depMode = DeploymentMode.fromOrdinal(depMode0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - byte[] evtsBytes0 = commState.getByteArray(); + evtsBytes = reader.readByteArray("evtsBytes"); - if (evtsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - evtsBytes = evtsBytes0; - - commState.idx++; + state++; case 3: - byte[] exBytes0 = commState.getByteArray(); + exBytes = reader.readByteArray("exBytes"); - if (exBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - exBytes = exBytes0; - - commState.idx++; + state++; case 4: - byte[] filter0 = commState.getByteArray(); + filter = reader.readByteArray("filter"); - if (filter0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - filter = filter0; - - commState.idx++; + state++; case 5: - String filterClsName0 = commState.getString(); + filterClsName = reader.readString("filterClsName"); - if (filterClsName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - filterClsName = filterClsName0; - - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (ldrParties == null) - ldrParties = U.newHashMap(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } - - IgniteUuid _val = commState.getGridUuid(); + ldrParties = reader.readMap("ldrParties", UUID.class, IgniteUuid.class, false); - if (_val == GRID_UUID_NOT_READ) - return false; - - ldrParties.put((UUID)commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - byte[] resTopicBytes0 = commState.getByteArray(); + resTopicBytes = reader.readByteArray("resTopicBytes"); - if (resTopicBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - resTopicBytes = resTopicBytes0; - - commState.idx++; + state++; case 8: - String userVer0 = commState.getString(); + userVer = reader.readString("userVer"); - if (userVer0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - userVer = userVer0; - - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java index f00b33fd0bcbf..ef999d76ab4a6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java @@ -321,6 +321,23 @@ public long swapKeys(@Nullable String spaceName) throws IgniteCheckedException { } } + /** + * Gets number of swap entries for given partitions. + * + * @param spaceName Space name. + * @param parts Partitions. + * @return Number of swap entries for given partitions. + * @throws IgniteCheckedException If failed. + */ + public long swapKeys(@Nullable String spaceName, Set parts) throws IgniteCheckedException { + try { + return getSpi().count(spaceName, parts); + } + catch (IgniteSpiException e) { + throw new IgniteCheckedException("Failed to get swap keys count for space: " + spaceName, e); + } + } + /** * @param spaceName Space name. * @throws IgniteCheckedException If failed. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java index ff44528819921..a5261e03ace69 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java @@ -27,7 +27,6 @@ import org.apache.ignite.internal.util.future.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import org.jdk8.backport.*; import org.jetbrains.annotations.*; @@ -277,7 +276,7 @@ public int partition(Object key) { try { key = ctx.marshalToPortable(key); } - catch (PortableException e) { + catch (IgniteException e) { U.error(log, "Failed to marshal key to portable: " + key, e); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java index 5ee9826714eda..cf268fd0b76f9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java @@ -397,7 +397,7 @@ private AffinityInfo affinityInfoFromNode(@Nullable String cacheName, long topVe f.reset(); m.reset(); - Boolean portableEnabled = U.portableEnabled(n, cacheName); + Boolean portableEnabled = ctx.portable().portableEnabled(n, cacheName); return new AffinityInfo(f, m, t.get3(), portableEnabled != null && portableEnabled); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl0.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl0.java new file mode 100644 index 0000000000000..05c30c35edd92 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl0.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import javax.cache.*; +import java.util.*; + +/** + * + */ +public class CacheEntryImpl0 implements Cache.Entry { + /** */ + private final Map.Entry e; + + /** + * @param e Entry. + */ + public CacheEntryImpl0(Map.Entry e) { + this.e = e; + } + + /** {@inheritDoc} */ + @Override public K getKey() { + return e.getKey(); + } + + /** {@inheritDoc} */ + @Override public V getValue() { + return e.getValue(); + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override public T unwrap(Class cls) { + if (!cls.equals(getClass())) + throw new IllegalArgumentException("Unwrapping to class is not supported: " + cls); + + return (T)this; + } + + /** {@inheritDoc} */ + public String toString() { + return "CacheEntry [key=" + getKey() + ", val=" + getValue() + ']'; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheWeakQueryIteratorsHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheWeakQueryIteratorsHolder.java index 245528c3010d0..0dbe9179239be 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheWeakQueryIteratorsHolder.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheWeakQueryIteratorsHolder.java @@ -126,7 +126,8 @@ public class WeakQueryFutureIterator extends GridCloseableIteratorAdapter /** Weak reference. */ private final WeakReference> weakRef; - CacheIteratorConverter convert; + /** */ + private final CacheIteratorConverter convert; /** Init flag. */ private boolean init; @@ -139,6 +140,7 @@ public class WeakQueryFutureIterator extends GridCloseableIteratorAdapter /** * @param fut GridCacheQueryFuture to iterate. + * @param convert Converter. */ WeakQueryFutureIterator(CacheQueryFuture fut, CacheIteratorConverter convert) { this.fut = fut; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java index a4e01fa91a8e5..b10e4ceeea1b7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java @@ -45,7 +45,6 @@ import org.apache.ignite.lang.*; import org.apache.ignite.mxbean.*; import org.apache.ignite.plugin.security.*; -import org.apache.ignite.portables.*; import org.apache.ignite.resources.*; import org.apache.ignite.transactions.*; import org.jdk8.backport.*; @@ -82,6 +81,12 @@ public abstract class GridCacheAdapter implements GridCache, /** clearLocally() split threshold. */ public static final int CLEAR_ALL_SPLIT_THRESHOLD = 10000; + /** Distribution modes to include into global size calculation. */ + private static final Set SIZE_NODES = EnumSet.of( + CacheDistributionMode.NEAR_PARTITIONED, + CacheDistributionMode.PARTITIONED_ONLY, + CacheDistributionMode.NEAR_ONLY); + /** Deserialization stash. */ private static final ThreadLocal> stash = new ThreadLocal>() { @@ -458,10 +463,6 @@ public GridCacheProjectionImpl keepPortable0() { Class keyType, Class valType ) { - if (PortableObject.class.isAssignableFrom(keyType) || PortableObject.class.isAssignableFrom(valType)) - throw new IllegalStateException("Failed to create cache projection for portable objects. " + - "Use keepPortable() method instead."); - if (ctx.deploymentEnabled()) { try { ctx.deploy().registerClasses(keyType, valType); @@ -655,102 +656,70 @@ public IgniteInternalFuture containsKeyAsync(K key, @Nullable IgnitePre } /** {@inheritDoc} */ - @SuppressWarnings("ForLoopReplaceableByForEach") - @Nullable @Override public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException { - A.notNull(key, "key"); - + @Override public Iterable> localEntries(CachePeekMode[] peekModes) throws IgniteCheckedException { assert peekModes != null; - if (keyCheck) - validateCacheKey(key); - ctx.checkSecurity(GridSecurityPermission.CACHE_READ); - boolean near = false; - boolean primary = false; - boolean backup = false; + PeekModes modes = parsePeekModes(peekModes); - boolean heap = false; - boolean offheap = false; - boolean swap = false; + List>> its = new ArrayList<>(); - if (peekModes.length == 0) { - near = true; - primary = true; - backup = true; + if (ctx.isLocal()) { + modes.primary = true; + modes.backup = true; - heap = true; - offheap = true; - swap = true; + if (modes.heap) + its.add(iterator(map.entries0().iterator(), !ctx.keepPortable())); } - else { - for (int i = 0; i < peekModes.length; i++) { - CachePeekMode peekMode = peekModes[i]; - - A.notNull(peekMode, "peekMode"); + else if (modes.heap) { + if (modes.near && ctx.isNear()) + its.add(ctx.near().nearEntriesIterator()); - switch (peekMode) { - case ALL: - near = true; - primary = true; - backup = true; - - heap = true; - offheap = true; - swap = true; - - break; + if (modes.primary || modes.backup) { + GridDhtCacheAdapter cache = ctx.isNear() ? ctx.near().dht() : ctx.dht(); - case BACKUP: - backup = true; - - break; - - case PRIMARY: - primary = true; - - break; - - case NEAR: - near = true; - - break; + its.add(cache.localEntriesIterator(modes.primary, modes.backup)); + } + } - case ONHEAP: - heap = true; + // Swap and offheap are disabled for near cache. + if (modes.primary || modes.backup) { + long topVer = ctx.affinity().affinityTopologyVersion(); - break; + GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap(); - case OFFHEAP: - offheap = true; + if (modes.swap) + its.add(swapMgr.swapIterator(modes.primary, modes.backup, topVer)); - break; + if (modes.offheap) + its.add(swapMgr.offheapIterator(modes.primary, modes.backup, topVer)); + } - case SWAP: - swap = true; + final Iterator> it = F.flatIterators(its); - break; + return new Iterable>() { + @Override public Iterator> iterator() { + return it; + } - default: - assert false : peekMode; - } + public String toString() { + return "CacheLocalEntries []"; } - } + }; + } - if (!(heap || offheap || swap)) { - heap = true; - offheap = true; - swap = true; - } + /** {@inheritDoc} */ + @SuppressWarnings("ForLoopReplaceableByForEach") + @Nullable @Override public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException { + A.notNull(key, "key"); - if (!(primary || backup || near)) { - primary = true; - backup = true; - near = true; - } + if (keyCheck) + validateCacheKey(key); - assert heap || offheap || swap; - assert primary || backup || near; + ctx.checkSecurity(GridSecurityPermission.CACHE_READ); + + PeekModes modes = parsePeekModes(peekModes); try { if (ctx.portableEnabled()) @@ -765,11 +734,11 @@ public IgniteInternalFuture containsKeyAsync(K key, @Nullable IgnitePre boolean nearKey; - if (!(near && primary && backup)) { + if (!(modes.near && modes.primary && modes.backup)) { boolean keyPrimary = ctx.affinity().primary(ctx.localNode(), part, topVer); if (keyPrimary) { - if (!primary) + if (!modes.primary) return null; nearKey = false; @@ -778,20 +747,20 @@ public IgniteInternalFuture containsKeyAsync(K key, @Nullable IgnitePre boolean keyBackup = ctx.affinity().belongs(ctx.localNode(), part, topVer); if (keyBackup) { - if (!backup) + if (!modes.backup) return null; nearKey = false; } else { - if (!near) + if (!modes.near) return null; nearKey = true; // Swap and offheap are disabled for near cache. - offheap = false; - swap = false; + modes.offheap = false; + modes.swap = false; } } } @@ -800,36 +769,36 @@ public IgniteInternalFuture containsKeyAsync(K key, @Nullable IgnitePre if (nearKey) { // Swap and offheap are disabled for near cache. - offheap = false; - swap = false; + modes.offheap = false; + modes.swap = false; } } if (nearKey && !ctx.isNear()) return null; - if (heap) { + if (modes.heap) { GridCacheEntryEx e = nearKey ? peekEx(key) : (ctx.isNear() ? ctx.near().dht().peekEx(key) : peekEx(key)); if (e != null) { - val = e.peek(heap, offheap, swap, topVer); + val = e.peek(modes.heap, modes.offheap, modes.swap, topVer); - offheap = false; - swap = false; + modes.offheap = false; + modes.swap = false; } } - if (offheap || swap) { + if (modes.offheap || modes.swap) { GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap(); - GridCacheSwapEntry swapEntry = swapMgr.read(key, offheap, swap); + GridCacheSwapEntry swapEntry = swapMgr.read(key, modes.offheap, modes.swap); val = swapEntry != null ? swapEntry.value() : null; } } else - val = localCachePeek0(key, heap, offheap, swap); + val = localCachePeek0(key, modes.heap, modes.offheap, modes.swap); if (ctx.portableEnabled()) val = (V)ctx.unwrapPortableIfNeeded(val, ctx.keepPortable()); @@ -1526,6 +1495,32 @@ private boolean clearLocally(GridCacheVersion obsoleteVer, K key, } } + /** {@inheritDoc} */ + @Override public IgniteInternalFuture clearAsync() { + Collection nodes = ctx.grid().forCacheNodes(name()).nodes(); + + if (!nodes.isEmpty()) { + IgniteInternalFuture fut = + ctx.closures().callAsyncNoFailover(BROADCAST, new GlobalClearAllCallable(name()), nodes, true); + + return fut.chain(new CX1, Object>() { + @Override public Object applyx(IgniteInternalFuture fut) throws IgniteCheckedException { + try { + return fut.get(); + } + catch (ClusterGroupEmptyCheckedException ignore) { + if (log.isDebugEnabled()) + log.debug("All remote nodes left while cache clearLocally [cacheName=" + name() + "]"); + + return null; + } + } + }); + } + else + return new GridFinishedFuture<>(ctx.kernalContext()); + } + /** {@inheritDoc} */ @Override public boolean compact(K key) throws IgniteCheckedException { return compact(key, (IgnitePredicate>[])null); @@ -1557,7 +1552,7 @@ private boolean evictx(K key, GridCacheVersion ver, try { key = (K)ctx.marshalToPortable(key); } - catch (PortableException e) { + catch (IgniteException e) { throw new IgniteException(e); } } @@ -3568,7 +3563,7 @@ public String toString() { try { key0 = (K)ctx.marshalToPortable(key); } - catch (PortableException e) { + catch (IgniteException e) { return new GridFinishedFuture<>(ctx.kernalContext(), e); } } @@ -3851,7 +3846,7 @@ protected void checkJta() throws IgniteCheckedException { ctx.store().loadCache(new CIX3() { @Override public void applyx(K key, V val, @Nullable GridCacheVersion ver) - throws PortableException { + throws IgniteException { assert ver == null; loadEntry(key, val, ver0, p, topVer, replicate, ttl); @@ -4065,6 +4060,99 @@ IgniteInternalFuture globalLoadCacheAsync(@Nullable IgniteBiPredicate p return e == null || e.obsolete() ? null : e.wrap(); } + /** {@inheritDoc} */ + @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException { + if (isLocal()) + return localSize(peekModes); + + return sizeAsync(peekModes).get(); + } + + /** {@inheritDoc} */ + @Override public IgniteInternalFuture sizeAsync(CachePeekMode[] peekModes) { + assert peekModes != null; + + PeekModes modes = parsePeekModes(peekModes); + + ClusterGroup grp; + + if (modes.near) + grp = ctx.grid().forCacheNodes(name(), SIZE_NODES); + else + grp = ctx.grid().forDataNodes(name()); + + Collection nodes = grp.nodes(); + + if (nodes.isEmpty()) + return new GridFinishedFuture<>(ctx.kernalContext(), 0); + + IgniteInternalFuture> fut = + ctx.closures().broadcastNoFailover(new SizeCallable(ctx.name(), peekModes), null, nodes); + + return fut.chain(new CX1>, Integer>() { + @Override public Integer applyx(IgniteInternalFuture> fut) + throws IgniteCheckedException { + Collection res = fut.get(); + + int totalSize = 0; + + for (Integer size : res) + totalSize += size; + + return totalSize; + } + }); + } + + /** {@inheritDoc} */ + @SuppressWarnings("ForLoopReplaceableByForEach") + @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException { + PeekModes modes = parsePeekModes(peekModes); + + int size = 0; + + if (ctx.isLocal()) { + modes.primary = true; + modes.backup = true; + + if (modes.heap) + size += size(); + } + else { + if (modes.heap) { + if (modes.near) + size += nearSize(); + + GridCacheAdapter cache = ctx.isNear() ? ctx.near().dht() : ctx.cache(); + + if (!(modes.primary && modes.backup)) { + if (modes.primary) + size += cache.primarySize(); + + if (modes.backup) + size += (cache.size() - cache.primarySize()); + } + else + size += cache.size(); + } + } + + // Swap and offheap are disabled for near cache. + if (modes.primary || modes.backup) { + long topVer = ctx.affinity().affinityTopologyVersion(); + + GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap(); + + if (modes.swap) + size += swapMgr.swapEntriesCount(modes.primary, modes.backup, topVer); + + if (modes.offheap) + size += swapMgr.offheapEntriesCount(modes.primary, modes.backup, topVer); + } + + return size; + } + /** {@inheritDoc} */ @Override public int size() { return map.publicSize(); @@ -4782,14 +4870,8 @@ public boolean containsKey(K key, @Nullable IgnitePredicate> f if (keyCheck) validateCacheKey(key); - if (ctx.portableEnabled()) { - try { - key = (K)ctx.marshalToPortable(key); - } - catch (PortableException e) { - throw new IgniteException(e); - } - } + if (ctx.portableEnabled()) + key = (K)ctx.marshalToPortable(key); GridCacheEntryEx e = peekEx(key); @@ -5249,6 +5331,232 @@ protected void validateCacheKeys(Iterable keys) { } } + /** + * @param it Internal entry iterator. + * @param deserializePortable Deserialize portable flag. + * @return Public API iterator. + */ + protected Iterator> iterator(final Iterator> it, + final boolean deserializePortable) { + return new Iterator>() { + { + advance(); + } + + /** */ + private Cache.Entry next; + + @Override public boolean hasNext() { + return next != null; + } + + @Override public Cache.Entry next() { + if (next == null) + throw new NoSuchElementException(); + + Cache.Entry e = next; + + advance(); + + return e; + } + + @Override public void remove() { + throw new UnsupportedOperationException(); + } + + /** + * Switch to next entry. + */ + private void advance() { + next = null; + + while (it.hasNext()) { + GridCacheEntryEx entry = it.next(); + + try { + next = toCacheEntry(entry, deserializePortable); + + if (next == null) + continue; + + break; + } + catch (IgniteCheckedException e) { + throw U.convertToCacheException(e); + } + catch (GridCacheEntryRemovedException ignore) { + // No-op. + } + } + } + }; + } + + /** + * @param entry Internal entry. + * @param deserializePortable Deserialize portable flag. + * @return Public API entry. + * @throws IgniteCheckedException If failed. + * @throws GridCacheEntryRemovedException If entry removed. + */ + @Nullable private Cache.Entry toCacheEntry(GridCacheEntryEx entry, + boolean deserializePortable) + throws IgniteCheckedException, GridCacheEntryRemovedException + { + try { + V val = entry.innerGet( + null, + false, + false, + false, + true, + false, + false, + false, + null, + null, + null, + null, + null); + + if (val == null) + return null; + + K key = entry.key(); + + if (deserializePortable && ctx.portableEnabled()) { + key = (K)ctx.unwrapPortableIfNeeded(key, true); + val = (V)ctx.unwrapPortableIfNeeded(val, true); + } + + return new CacheEntryImpl<>(key, val); + } + catch (GridCacheFilterFailedException ignore) { + assert false; + + return null; + } + } + + /** + * + */ + private static class PeekModes { + /** */ + boolean near; + + /** */ + boolean primary; + + /** */ + boolean backup; + + /** */ + boolean heap; + + /** */ + boolean offheap; + + /** */ + boolean swap; + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(PeekModes.class, this); + } + } + + /** + * @param peekModes Cache peek modes array. + * @return Peek modes flags. + */ + private static PeekModes parsePeekModes(CachePeekMode[] peekModes) { + assert peekModes != null; + + PeekModes modes = new PeekModes(); + + if (peekModes.length == 0) { + modes.near = true; + modes.primary = true; + modes.backup = true; + + modes.heap = true; + modes.offheap = true; + modes.swap = true; + } + else { + for (int i = 0; i < peekModes.length; i++) { + CachePeekMode peekMode = peekModes[i]; + + A.notNull(peekMode, "peekMode"); + + switch (peekMode) { + case ALL: + modes.near = true; + modes.primary = true; + modes.backup = true; + + modes.heap = true; + modes.offheap = true; + modes.swap = true; + + break; + + case BACKUP: + modes.backup = true; + + break; + + case PRIMARY: + modes.primary = true; + + break; + + case NEAR: + modes.near = true; + + break; + + case ONHEAP: + modes.heap = true; + + break; + + case OFFHEAP: + modes.offheap = true; + + break; + + case SWAP: + modes.swap = true; + + break; + + default: + assert false : peekMode; + } + } + } + + if (!(modes.heap || modes.offheap || modes.swap)) { + modes.heap = true; + modes.offheap = true; + modes.swap = true; + } + + if (!(modes.primary || modes.backup || modes.near)) { + modes.primary = true; + modes.backup = true; + modes.near = true; + } + + assert modes.heap || modes.offheap || modes.swap; + assert modes.primary || modes.backup || modes.near; + + return modes; + } + /** * @param plc Explicitly specified expiry policy for cache operation. * @return Expiry policy wrapper. @@ -5443,7 +5751,79 @@ private GlobalClearAllCallable(String cacheName) { } /** - * Internal callable which performs {@link org.apache.ignite.cache.CacheProjection#size()} or {@link org.apache.ignite.cache.CacheProjection#primarySize()} + * Internal callable for global size calculation. + */ + @GridInternal + private static class SizeCallable extends IgniteClosureX implements Externalizable { + /** */ + private static final long serialVersionUID = 0L; + + /** Cache name. */ + private String cacheName; + + /** Peek modes. */ + private CachePeekMode[] peekModes; + + /** Injected grid instance. */ + @IgniteInstanceResource + private Ignite ignite; + + /** + * Required by {@link Externalizable}. + */ + public SizeCallable() { + // No-op. + } + + /** + * @param cacheName Cache name. + * @param peekModes Cache peek modes. + */ + private SizeCallable(String cacheName, CachePeekMode[] peekModes) { + this.cacheName = cacheName; + this.peekModes = peekModes; + } + + /** {@inheritDoc} */ + @Override public Integer applyx(Object o) throws IgniteCheckedException { + GridCache cache = ((IgniteEx)ignite).cachex(cacheName); + + assert cache != null : cacheName; + + return cache.localSize(peekModes); + } + + /** {@inheritDoc} */ + @SuppressWarnings("ForLoopReplaceableByForEach") + @Override public void writeExternal(ObjectOutput out) throws IOException { + U.writeString(out, cacheName); + + out.writeInt(peekModes.length); + + for (int i = 0; i < peekModes.length; i++) + U.writeEnum(out, peekModes[i]); + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + cacheName = U.readString(in); + + int len = in.readInt(); + + peekModes = new CachePeekMode[len]; + + for (int i = 0; i < len; i++) + peekModes[i] = CachePeekMode.fromOrdinal(in.readByte()); + } + + /** {@inheritDoc} */ + public String toString() { + return S.toString(SizeCallable.class, this); + } + } + + /** + * Internal callable which performs {@link CacheProjection#size()} or {@link CacheProjection#primarySize()} * operation on a cache with the given name. */ @GridInternal diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java index 999ad66df80ba..b0cfb6b0db212 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java @@ -157,9 +157,6 @@ public class GridCacheAttributes implements Externalizable { /** Store load previous value flag. */ private boolean loadPrevVal; - /** Portable enabled flag. */ - private boolean portableEnabled; - /** * @param cfg Cache configuration. * @param store Cache store. @@ -176,7 +173,6 @@ public GridCacheAttributes(CacheConfiguration cfg, @Nullable CacheStore st loadPrevVal = cfg.isLoadPreviousValue(); name = cfg.getName(); partDistro = GridCacheUtils.distributionMode(cfg); - portableEnabled = cfg.isPortableEnabled(); preloadBatchSize = cfg.getPreloadBatchSize(); preloadMode = cfg.getPreloadMode(); qryIdxEnabled = cfg.isQueryIndexEnabled(); @@ -521,13 +517,6 @@ public String indexingSpiName() { return indexingSpiName; } - /** - * @return Portable enabled flag. - */ - public boolean portableEnabled() { - return portableEnabled; - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeEnum(out, atomicityMode); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index e8192b985ec96..492b90d2d65d3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -37,6 +37,7 @@ import org.apache.ignite.internal.processors.cache.local.*; import org.apache.ignite.internal.processors.cache.query.*; import org.apache.ignite.internal.processors.cache.query.continuous.*; +import org.apache.ignite.internal.processors.cache.serialization.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.processors.closure.*; @@ -52,7 +53,6 @@ import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.*; import org.apache.ignite.plugin.security.*; -import org.apache.ignite.portables.*; import org.jetbrains.annotations.*; import javax.cache.*; @@ -131,6 +131,9 @@ public class GridCacheContext implements Externalizable { /** Replication manager. */ private GridCacheDrManager drMgr; + /** Serialization manager. */ + private IgniteCacheSerializationManager serMgr; + /** JTA manager. */ private CacheJtaManagerAdapter jtaMgr; @@ -238,6 +241,7 @@ public GridCacheContext( CacheDataStructuresManager dataStructuresMgr, GridCacheTtlManager ttlMgr, GridCacheDrManager drMgr, + IgniteCacheSerializationManager serMgr, CacheJtaManagerAdapter jtaMgr) { assert ctx != null; assert sharedCtx != null; @@ -271,6 +275,7 @@ public GridCacheContext( this.dataStructuresMgr = add(dataStructuresMgr); this.ttlMgr = add(ttlMgr); this.drMgr = add(drMgr); + this.serMgr = add(serMgr); this.jtaMgr = add(jtaMgr); log = ctx.log(getClass()); @@ -1578,11 +1583,11 @@ public boolean conflictNeedResolve(GridCacheVersion oldVer, GridCacheVersion new * @return Conflict resolution result. * @throws IgniteCheckedException In case of exception. */ - public GridCacheVersionConflictContextImpl conflictResolve(GridCacheVersionedEntryEx oldEntry, + public GridCacheVersionConflictContext conflictResolve(GridCacheVersionedEntryEx oldEntry, GridCacheVersionedEntryEx newEntry, boolean atomicVerComparator) throws IgniteCheckedException { assert conflictRslvr != null : "Should not reach this place."; - GridCacheVersionConflictContextImpl ctx = conflictRslvr.resolve(oldEntry, newEntry, atomicVerComparator); + GridCacheVersionConflictContext ctx = conflictRslvr.resolve(oldEntry, newEntry, atomicVerComparator); if (ctx.isManualResolve()) drMgr.onReceiveCacheConflictResolved(ctx.isUseNew(), ctx.isUseOld(), ctx.isMerge()); @@ -1611,7 +1616,7 @@ public void onDeferredDelete(GridCacheEntryEx entry, GridCacheVersion ver) } /** - * @param interceptorRes Result of {@link org.apache.ignite.cache.CacheInterceptor#onBeforeRemove} callback. + * @param interceptorRes Result of {@link CacheInterceptor#onBeforeRemove} callback. * @return {@code True} if interceptor cancels remove. */ public boolean cancelRemove(@Nullable IgniteBiTuple interceptorRes) { @@ -1643,7 +1648,14 @@ public GridPortableProcessor portable() { * @return Portable enabled flag. */ public boolean portableEnabled() { - return cacheCfg.isPortableEnabled(); + return serMgr.portableEnabled(); + } + + /** + * @return Keep portable in store flag. + */ + public boolean keepPortableInStore() { + return serMgr.keepPortableInStore(); } /** @@ -1689,15 +1701,15 @@ public byte[] convertPortableBytes(byte[] bytes) throws IgniteCheckedException { /** * @param obj Object. * @return Portable object. - * @throws PortableException In case of error. + * @throws IgniteException In case of error. */ - @Nullable public Object marshalToPortable(@Nullable Object obj) throws PortableException { + @Nullable public Object marshalToPortable(@Nullable Object obj) throws IgniteException { assert portableEnabled(); if (obj == null) return null; - if (obj instanceof PortableObject || obj instanceof GridCacheInternal) + if (ctx.portable().isPortableObject(obj) || obj instanceof GridCacheInternal) return obj; GridPortableProcessor proc = kernalContext().portable(); @@ -1715,58 +1727,7 @@ public byte[] convertPortableBytes(byte[] bytes) throws IgniteCheckedException { * @return Unwrapped collection. */ public Collection unwrapPortablesIfNeeded(Collection col, boolean keepPortable) { - if (keepPortable || !config().isPortableEnabled()) - return col; - - if (col instanceof ArrayList) - return unwrapPortables((ArrayList)col); - - Collection col0 = new ArrayList<>(col.size()); - - for (Object obj : col) - col0.add(unwrapPortable(obj)); - - return col0; - } - - /** - * Unwraps map. - * - * @param map Map to unwrap. - * @param keepPortable Keep portable flag. - * @return Unwrapped collection. - */ - public Map unwrapPortablesIfNeeded(Map map, boolean keepPortable) { - if (keepPortable || !config().isPortableEnabled()) - return map; - - Map map0 = U.newHashMap(map.size()); - - for (Map.Entry e : map.entrySet()) - map0.put(unwrapPortable(e.getKey()), unwrapPortable(e.getValue())); - - return map0; - } - - /** - * Unwraps array list. - * - * @param col List to unwrap. - * @return Unwrapped list. - */ - private Collection unwrapPortables(ArrayList col) { - int size = col.size(); - - for (int i = 0; i < size; i++) { - Object o = col.get(i); - - Object unwrapped = unwrapPortable(o); - - if (o != unwrapped) - col.set(i, unwrapped); - } - - return col; + return serMgr.unwrapPortablesIfNeeded(col, keepPortable); } /** @@ -1778,53 +1739,7 @@ private Collection unwrapPortables(ArrayList col) { */ @SuppressWarnings("IfMayBeConditional") public Object unwrapPortableIfNeeded(Object o, boolean keepPortable) { - assert !portableEnabled() || o == null || U.isPortableOrCollectionType(o.getClass()); - - if (o == null) - return null; - - if (keepPortable || !portableEnabled()) - return o; - - return unwrapPortable(o); - } - - /** - * @param o Object to unwrap. - * @return Unwrapped object. - */ - private Object unwrapPortable(Object o) { - if (o instanceof Map.Entry) { - Map.Entry entry = (Map.Entry)o; - - Object key = entry.getKey(); - - boolean unwrapped = false; - - if (key instanceof PortableObject) { - key = ((PortableObject)key).deserialize(); - - unwrapped = true; - } - - Object val = entry.getValue(); - - if (val instanceof PortableObject) { - val = ((PortableObject)val).deserialize(); - - unwrapped = true; - } - - return unwrapped ? F.t(key, val) : o; - } - else if (o instanceof Collection) - return unwrapPortablesIfNeeded((Collection)o, false); - else if (o instanceof Map) - return unwrapPortablesIfNeeded((Map)o, false); - else if (o instanceof PortableObject) - return ((PortableObject)o).deserialize(); - - return o; + return serMgr.unwrapPortableIfNeeded(o, keepPortable); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java index d89c9fcbfc4bf..2b6bfc94d0ccf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java @@ -19,30 +19,35 @@ import org.apache.ignite.*; import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.*; import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import org.apache.ignite.resources.*; import java.lang.annotation.*; import java.lang.reflect.*; /** - * Default key affinity mapper. If key class has annotation {@link org.apache.ignite.cache.affinity.CacheAffinityKeyMapped}, + * Default key affinity mapper. If key class has annotation {@link CacheAffinityKeyMapped}, * then the value of annotated method or field will be used to get affinity value instead * of the key itself. If there is no annotation, then the key is used as is. *

      - * Convenience affinity key adapter, {@link org.apache.ignite.cache.affinity.CacheAffinityKey} can be used in + * Convenience affinity key adapter, {@link CacheAffinityKey} can be used in * conjunction with this mapper to automatically provide custom affinity keys for cache keys. *

      * If non-default affinity mapper is used, is should be provided via - * {@link org.apache.ignite.configuration.CacheConfiguration#getAffinityMapper()} configuration property. + * {@link CacheConfiguration#getAffinityMapper()} configuration property. */ public class GridCacheDefaultAffinityKeyMapper implements CacheAffinityKeyMapper { /** */ private static final long serialVersionUID = 0L; + /** Injected ignite instance. */ + @IgniteInstanceResource + private Ignite ignite; + /** Reflection cache. */ private GridReflectionCache reflectCache = new GridReflectionCache( new P1() { @@ -74,7 +79,7 @@ public class GridCacheDefaultAffinityKeyMapper implements CacheAffinityKeyMapper private transient IgniteLogger log; /** - * If key class has annotation {@link org.apache.ignite.cache.affinity.CacheAffinityKeyMapped}, + * If key class has annotation {@link CacheAffinityKeyMapped}, * then the value of annotated method or field will be used to get affinity value instead * of the key itself. If there is no annotation, then the key is returned as is. * @@ -84,23 +89,10 @@ public class GridCacheDefaultAffinityKeyMapper implements CacheAffinityKeyMapper @Override public Object affinityKey(Object key) { GridArgumentCheck.notNull(key, "key"); - if (key instanceof PortableObject) { - PortableObject po = (PortableObject)key; - - try { - PortableMetadata meta = po.metaData(); - - if (meta != null) { - String affKeyFieldName = meta.affinityKeyFieldName(); + IgniteKernal kernal = (IgniteKernal)ignite; - if (affKeyFieldName != null) - return po.field(affKeyFieldName); - } - } - catch (PortableException e) { - U.error(log, "Failed to get affinity field from portable object: " + key, e); - } - } + if (kernal.context().portable().isPortableObject(key)) + return kernal.context().portable().affinityKey(key); else { try { Object o = reflectCache.firstFieldValue(key); 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 3465efdca36bc..ce7d4d763a36b 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 @@ -20,11 +20,11 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -141,7 +141,7 @@ void addKey(K key, GridCacheVersion ver, boolean near) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCacheEvictionRequest _clone = new GridCacheEvictionRequest(); clone0(_clone); @@ -150,7 +150,7 @@ void addKey(K key, GridCacheVersion ver, boolean near) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCacheEvictionRequest _clone = (GridCacheEvictionRequest)_msg; @@ -164,36 +164,36 @@ void addKey(K key, GridCacheVersion ver, boolean near) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putByteArray(entriesBytes)) + if (!writer.writeByteArray("entriesBytes", entriesBytes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putLong(futId)) + if (!writer.writeLong("futId", futId)) return false; - commState.idx++; + state++; case 5: - if (!commState.putLong(topVer)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; } @@ -203,37 +203,35 @@ void addKey(K key, GridCacheVersion ver, boolean near) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - byte[] entriesBytes0 = commState.getByteArray(); + entriesBytes = reader.readByteArray("entriesBytes"); - if (entriesBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - entriesBytes = entriesBytes0; - - commState.idx++; + state++; case 4: - if (buf.remaining() < 8) - return false; + futId = reader.readLong("futId"); - futId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - if (buf.remaining() < 8) - return false; + topVer = reader.readLong("topVer"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -242,7 +240,7 @@ void addKey(K key, GridCacheVersion ver, boolean near) { /** {@inheritDoc} */ @Override public byte directType() { - return 16; + return 14; } /** {@inheritDoc} */ 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 afd1e6acedde4..2687e95b07318 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 @@ -19,9 +19,9 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -130,7 +130,7 @@ boolean error() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCacheEvictionResponse _clone = new GridCacheEvictionResponse(); clone0(_clone); @@ -139,7 +139,7 @@ boolean error() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCacheEvictionResponse _clone = (GridCacheEvictionResponse)_msg; @@ -153,57 +153,36 @@ boolean error() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putBoolean(err)) + if (!writer.writeBoolean("err", err)) return false; - commState.idx++; + state++; case 4: - if (!commState.putLong(futId)) + if (!writer.writeLong("futId", futId)) return false; - commState.idx++; + state++; case 5: - if (rejectedKeyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(rejectedKeyBytes.size())) - return false; - - commState.it = rejectedKeyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("rejectedKeyBytes", rejectedKeyBytes, byte[].class)) + return false; - commState.idx++; + state++; } @@ -213,56 +192,35 @@ boolean error() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (buf.remaining() < 1) - return false; + err = reader.readBoolean("err"); - err = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (buf.remaining() < 8) - return false; + futId = reader.readLong("futId"); - futId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (rejectedKeyBytes == null) - rejectedKeyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + rejectedKeyBytes = reader.readCollection("rejectedKeyBytes", byte[].class); - if (_val == BYTE_ARR_NOT_READ) - return false; - - rejectedKeyBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -271,7 +229,7 @@ boolean error() { /** {@inheritDoc} */ @Override public byte directType() { - return 17; + return 15; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java index 69d151e802d67..c13be533b3b8b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java @@ -358,23 +358,12 @@ public void send(ClusterNode node, GridCacheMessage msg, GridIoPolicy plc) log.debug("Sending cache message [msg=" + msg + ", node=" + U.toShortString(node) + ']'); int cnt = 0; - boolean first = true; while (cnt <= retryCnt) { try { cnt++; - GridCacheMessage msg0; - - if (first) { - msg0 = msg; - - first = false; - } - else - msg0 = (GridCacheMessage)msg.clone(); - - cctx.gridIO().send(node, TOPIC_CACHE, msg0, plc); + cctx.gridIO().send(node, TOPIC_CACHE, msg, plc); return; } @@ -426,7 +415,6 @@ public boolean safeSend(Collection nodes, GridCacheMessag final Collection leftIds = new GridLeanSet<>(); int cnt = 0; - boolean first = true; while (cnt < retryCnt) { try { @@ -436,17 +424,7 @@ public boolean safeSend(Collection nodes, GridCacheMessag } }); - GridCacheMessage msg0; - - if (first) { - msg0 = msg; - - first = false; - } - else - msg0 = (GridCacheMessage)msg.clone(); - - cctx.gridIO().send(nodesView, TOPIC_CACHE, msg0, SYSTEM_POOL); + cctx.gridIO().send(nodesView, TOPIC_CACHE, msg, SYSTEM_POOL); boolean added = false; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java index fe24d96b7bf44..40bac3735a0ff 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java @@ -1657,7 +1657,7 @@ else if (log.isDebugEnabled()) GridCacheVersion enqueueVer = null; - GridCacheVersionConflictContextImpl drRes = null; + GridCacheVersionConflictContext drRes = null; EntryProcessorResult invokeRes = null; 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 e70187b3d776a..3b07bc73af820 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 @@ -21,11 +21,11 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.managers.deployment.*; import org.apache.ignite.internal.processors.cache.transactions.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import javax.cache.*; @@ -36,7 +36,7 @@ /** * Parent of all cache messages. */ -public abstract class GridCacheMessage extends GridTcpCommunicationMessageAdapter { +public abstract class GridCacheMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -646,7 +646,7 @@ protected final void unmarshalTx(Iterable> txEntries, } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridCacheMessage _clone = (GridCacheMessage)_msg; _clone.msgId = msgId; @@ -659,33 +659,33 @@ protected final void unmarshalTx(Iterable> txEntries, /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putInt(cacheId)) + if (!writer.writeInt("cacheId", cacheId)) return false; - commState.idx++; + state++; case 1: - if (!commState.putMessage(depInfo)) + if (!writer.writeMessage("depInfo", depInfo)) return false; - commState.idx++; + state++; case 2: - if (!commState.putLong(msgId)) + if (!writer.writeLong("msgId", msgId)) return false; - commState.idx++; + state++; } @@ -695,34 +695,32 @@ protected final void unmarshalTx(Iterable> txEntries, /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - if (buf.remaining() < 4) - return false; + cacheId = reader.readInt("cacheId"); - cacheId = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 1: - Object depInfo0 = commState.getMessage(); + depInfo = reader.readMessage("depInfo"); - if (depInfo0 == MSG_NOT_READ) + if (!reader.isLastRead()) return false; - depInfo = (GridDeploymentInfoBean)depInfo0; - - commState.idx++; + state++; case 2: - if (buf.remaining() < 8) - return false; + msgId = reader.readLong("msgId"); - msgId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java index 8f9fb929a99d0..42fcb4bf1c4f5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java @@ -273,14 +273,28 @@ public class GridCachePartitionExchangeManager extends GridCacheSharedMana U.join(exchWorker, log); - exchFuts = null; - ResendTimeoutObject resendTimeoutObj = pendingResend.getAndSet(null); if (resendTimeoutObj != null) cctx.time().removeTimeoutObject(resendTimeoutObj); } + /** {@inheritDoc} */ + @SuppressWarnings("LockAcquiredButNotSafelyReleased") + @Override protected void stop0(boolean cancel) { + super.stop0(cancel); + + // Do not allow any activity in exchange manager after stop. + busyLock.writeLock().lock(); + + exchFuts = null; + } + + /** + * @param cacheId Cache ID. + * @param exchId Exchange ID. + * @return Topology. + */ public GridDhtPartitionTopology clientTopology(int cacheId, GridDhtPartitionExchangeId exchId) { GridClientPartitionTopology top = clientTops.get(cacheId); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java index 4efebf9520772..53427d57fc554 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java @@ -39,6 +39,7 @@ import org.apache.ignite.internal.processors.cache.local.atomic.*; import org.apache.ignite.internal.processors.cache.query.*; import org.apache.ignite.internal.processors.cache.query.continuous.*; +import org.apache.ignite.internal.processors.cache.serialization.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; @@ -450,10 +451,6 @@ else if (cc.getPreloadMode() == SYNC) { if (cc.getAtomicityMode() == ATOMIC) assertParameter(cc.getTransactionManagerLookupClassName() == null, "transaction manager can not be used with ATOMIC cache"); - - if (cc.isPortableEnabled() && !ctx.isEnterprise()) - throw new IgniteCheckedException("Portable mode for cache is supported only in Enterprise edition " + - "(set 'portableEnabled' property to 'false') [cacheName=" + cc.getName() + ']'); } /** @@ -634,6 +631,7 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near CacheDataStructuresManager dataStructuresMgr = new CacheDataStructuresManager(); GridCacheTtlManager ttlMgr = new GridCacheTtlManager(); GridCacheDrManager drMgr = ctx.createComponent(GridCacheDrManager.class); + IgniteCacheSerializationManager serMgr = ctx.createComponent(IgniteCacheSerializationManager.class); GridCacheStoreManager storeMgr = new GridCacheStoreManager(ctx, sesHolders, cfgStore, cfg); @@ -656,6 +654,7 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near dataStructuresMgr, ttlMgr, drMgr, + serMgr, jta); GridCacheAdapter cache = null; @@ -773,6 +772,7 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near evictMgr = new GridCacheEvictionManager(); evtMgr = new GridCacheEventManager(); drMgr = ctx.createComponent(GridCacheDrManager.class); + serMgr = ctx.createComponent(IgniteCacheSerializationManager.class); cacheCtx = new GridCacheContext( ctx, @@ -793,6 +793,7 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near dataStructuresMgr, ttlMgr, drMgr, + serMgr, jta); GridDhtCacheAdapter dht = null; @@ -1175,9 +1176,6 @@ private void checkCache(ClusterNode rmt) throws IgniteCheckedException { CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "queryIndexEnabled", "Query index enabled", locAttr.queryIndexEnabled(), rmtAttr.queryIndexEnabled(), true); - CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "portableEnabled", - "Portables enabled", locAttr.portableEnabled(), rmtAttr.portableEnabled(), true); - if (locAttr.cacheMode() == PARTITIONED) { CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "evictSynchronized", "Eviction synchronized", locAttr.evictSynchronized(), rmtAttr.evictSynchronized(), diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java index 205a52565457b..9986be7ae3af9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java @@ -32,7 +32,6 @@ import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; -import org.apache.ignite.portables.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; @@ -417,15 +416,6 @@ private IgnitePredicate> visitor(final IgnitePredicate> visitor(final IgnitePredicate sizeAsync(CachePeekMode[] peekModes) { + return cache.sizeAsync(peekModes); + } + /** {@inheritDoc} */ @Override public int globalSize() throws IgniteCheckedException { return cache.globalSize(); @@ -1010,6 +1015,11 @@ private IgnitePredicate> visitor(final IgnitePredicate> localEntries(CachePeekMode[] peekModes) throws IgniteCheckedException { + return cache.localEntries(peekModes); + } + /** {@inheritDoc} */ @Override public V peek(K key, @Nullable Collection modes) throws IgniteCheckedException { V val = cache.peek(key, modes); @@ -1052,6 +1062,11 @@ private IgnitePredicate> visitor(final IgnitePredicate clearAsync() { + return cache.clearAsync(); + } + /** {@inheritDoc} */ @Override public void clear(long timeout) throws IgniteCheckedException { cache.clear(timeout); @@ -1185,6 +1200,11 @@ private IgnitePredicate> visitor(final IgnitePredicate removeAllAsync() { + return removeAllAsync(new IgnitePredicate[0]); + } + /** {@inheritDoc} */ @Override public IgniteInternalFuture removeAllAsync(@Nullable IgnitePredicate>... filter) { return cache.removeAllAsync(and(filter, false)); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java index 7d6168f94fb09..542fd19ec3fe3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java @@ -1231,6 +1231,18 @@ public GridCacheProjectionImpl gateProjection() { } } + /** {@inheritDoc} */ + @Override public Iterable> localEntries(CachePeekMode[] peekModes) throws IgniteCheckedException { + GridCacheProjectionImpl prev = gate.enter(prj); + + try { + return delegate.localEntries(peekModes); + } + finally { + gate.leave(prev); + } + } + /** {@inheritDoc} */ @Nullable @Override public V peek(K key, @Nullable Collection modes) throws IgniteCheckedException { GridCacheProjectionImpl prev = gate.enter(prj); @@ -1315,6 +1327,18 @@ public GridCacheProjectionImpl gateProjection() { } } + /** {@inheritDoc} */ + @Override public IgniteInternalFuture clearAsync() { + GridCacheProjectionImpl prev = gate.enter(prj); + + try { + return delegate.clearAsync(); + } + finally { + gate.leave(prev); + } + } + /** {@inheritDoc} */ @Override public void clear(long timeout) throws IgniteCheckedException { GridCacheProjectionImpl prev = gate.enter(prj); @@ -1602,6 +1626,18 @@ public GridCacheProjectionImpl gateProjection() { } } + /** {@inheritDoc} */ + @Override public IgniteInternalFuture removeAllAsync() { + GridCacheProjectionImpl prev = gate.enter(prj); + + try { + return delegate.removeAllAsync(); + } + finally { + gate.leave(prev); + } + } + /** {@inheritDoc} */ @Override public IgniteInternalFuture removeAllAsync(@Nullable IgnitePredicate>[] filter) { GridCacheProjectionImpl prev = gate.enter(prj); @@ -1727,6 +1763,42 @@ public GridCacheProjectionImpl gateProjection() { } } + /** {@inheritDoc} */ + @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException { + GridCacheProjectionImpl prev = gate.enter(prj); + + try { + return delegate.size(peekModes); + } + finally { + gate.leave(prev); + } + } + + /** {@inheritDoc} */ + @Override public IgniteInternalFuture sizeAsync(CachePeekMode[] peekModes) { + GridCacheProjectionImpl prev = gate.enter(prj); + + try { + return delegate.sizeAsync(peekModes); + } + finally { + gate.leave(prev); + } + } + + /** {@inheritDoc} */ + @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException { + GridCacheProjectionImpl prev = gate.enter(prj); + + try { + return delegate.localSize(peekModes); + } + finally { + gate.leave(prev); + } + } + /** {@inheritDoc} */ @Override public int globalSize() throws IgniteCheckedException { GridCacheProjectionImpl prev = gate.enter(prj); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java index 1f6fbfaac92ef..e301d8465998b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java @@ -183,9 +183,9 @@ private CacheStore cacheStoreWrapper(GridKernalContext ctx, } } - boolean convertPortable = !cctx.config().isKeepPortableInStore(); + boolean convertPortable = !cctx.keepPortableInStore(); - if (cctx.config().isPortableEnabled()) + if (cctx.portableEnabled()) this.convertPortable = convertPortable; else if (convertPortable) U.warn(log, "CacheConfiguration.isKeepPortableInStore() configuration property will " + diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java index a1e0fa1590804..2f9e9fb1895c6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java @@ -33,6 +33,7 @@ import org.jdk8.backport.*; import org.jetbrains.annotations.*; +import javax.cache.*; import java.lang.ref.*; import java.nio.*; import java.util.*; @@ -169,6 +170,52 @@ public long swapSize() throws IgniteCheckedException { return enabled ? swapMgr.swapSize(spaceName) : -1; } + /** + * @param primary If {@code true} includes primary entries. + * @param backup If {@code true} includes backup entries. + * @param topVer Topology version. + * @return Number of swap entries. + * @throws IgniteCheckedException If failed. + */ + public int swapEntriesCount(boolean primary, boolean backup, long topVer) throws IgniteCheckedException { + assert primary || backup; + + if (!swapEnabled) + return 0; + + if (!(primary && backup)) { + Set parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) : + cctx.affinity().backupPartitions(cctx.localNodeId(), topVer); + + return (int)swapMgr.swapKeys(spaceName, parts); + } + else + return (int)swapMgr.swapKeys(spaceName); + } + + /** + * @param primary If {@code true} includes primary entries. + * @param backup If {@code true} includes backup entries. + * @param topVer Topology version. + * @return Number of offheap entries. + * @throws IgniteCheckedException If failed. + */ + public int offheapEntriesCount(boolean primary, boolean backup, long topVer) throws IgniteCheckedException { + assert primary || backup; + + if (!offheapEnabled) + return 0; + + if (!(primary && backup)) { + Set parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) : + cctx.affinity().backupPartitions(cctx.localNodeId(), topVer); + + return (int)offheap.entriesCount(spaceName, parts); + } + else + return (int)offheap.entriesCount(spaceName); + } + /** * Gets number of swap entries (keys). * @@ -1463,6 +1510,66 @@ public GridCloseableIterator> rawSwapIterator() throws return swapMgr.rawIterator(spaceName); } + /** + * @param primary If {@code true} includes primary entries. + * @param backup If {@code true} includes backup entries. + * @param topVer Topology version. + * @return Swap entries iterator. + * @throws IgniteCheckedException If failed. + */ + public Iterator> swapIterator(boolean primary, boolean backup, long topVer) + throws IgniteCheckedException + { + assert primary || backup; + + if (!swapEnabled) + return F.emptyIterator(); + + if (primary && backup) + return cacheEntryIterator(lazySwapIterator()); + + Set parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) : + cctx.affinity().backupPartitions(cctx.localNodeId(), topVer); + + return new PartitionsIterator(parts) { + @Override protected GridCloseableIterator> partitionIterator(int part) + throws IgniteCheckedException + { + return swapMgr.rawIterator(spaceName, part); + } + }; + } + + /** + * @param primary If {@code true} includes primary entries. + * @param backup If {@code true} includes backup entries. + * @param topVer Topology version. + * @return Offheap entries iterator. + * @throws IgniteCheckedException If failed. + */ + public Iterator> offheapIterator(boolean primary, boolean backup, long topVer) + throws IgniteCheckedException + { + assert primary || backup; + + if (!offheapEnabled) + return F.emptyIterator(); + + if (primary && backup) + return cacheEntryIterator(lazyOffHeapIterator()); + + Set parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) : + cctx.affinity().backupPartitions(cctx.localNodeId(), topVer); + + return new PartitionsIterator(parts) { + @Override protected GridCloseableIterator> partitionIterator(int part) + throws IgniteCheckedException + { + return offheap.iterator(spaceName, part); + } + }; + } + /** * @param ldr Undeployed class loader. * @return Undeploy count. @@ -1563,6 +1670,19 @@ int iteratorSetSize() { return itSet.size(); } + /** + * @param it Map.Entry iterator. + * @return Cache.Entry iterator. + */ + private static Iterator> cacheEntryIterator(Iterator> it) { + return F.iterator(it, new C1, Cache.Entry>() { + @Override public Cache.Entry apply(Map.Entry e) { + // Create Cache.Entry over Map.Entry to do not deserialize keys/values if not needed. + return new CacheEntryImpl0<>(e); + } + }, true); + } + /** * */ @@ -1641,4 +1761,90 @@ private static class KeySwapListener implements GridCacheSwapListener> { + /** */ + private Iterator partIt; + + /** */ + private Iterator> curIt; + + /** */ + private Cache.Entry next; + + /** + * @param parts Partitions + */ + public PartitionsIterator(Collection parts) { + this.partIt = parts.iterator(); + + advance(); + } + + /** {@inheritDoc} */ + @Override public boolean hasNext() { + return next != null; + } + + /** {@inheritDoc} */ + @Override public Cache.Entry next() { + if (next == null) + throw new NoSuchElementException(); + + Cache.Entry e = next; + + advance(); + + return e; + } + + /** {@inheritDoc} */ + @Override public void remove() { + throw new UnsupportedOperationException(); + } + + /** + * Switches to next element. + */ + private void advance() { + next = null; + + do { + if (curIt == null) { + if (partIt.hasNext()) { + int part = partIt.next(); + + try { + curIt = cacheEntryIterator(lazyIterator(partitionIterator(part))); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + } + + if (curIt != null) { + if (curIt.hasNext()) { + next = curIt.next(); + + break; + } + else + curIt = null; + } + } + while (partIt.hasNext()); + } + + /** + * @param part Partition. + * @return Iterator for given partition. + * @throws IgniteCheckedException If failed. + */ + abstract protected GridCloseableIterator> partitionIterator(int part) + throws IgniteCheckedException; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUpdateAtomicResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUpdateAtomicResult.java index 16ab38d592caf..cabfaa5a3fd74 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUpdateAtomicResult.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUpdateAtomicResult.java @@ -51,7 +51,7 @@ public class GridCacheUpdateAtomicResult { /** DR resolution result. */ @GridToStringInclude - private final GridCacheVersionConflictContextImpl drRes; + private final GridCacheVersionConflictContext drRes; /** Whether update should be propagated to DHT node. */ private final boolean sndToDht; @@ -79,7 +79,7 @@ public GridCacheUpdateAtomicResult(boolean success, long newTtl, long drExpireTime, @Nullable GridCacheVersion rmvVer, - @Nullable GridCacheVersionConflictContextImpl drRes, + @Nullable GridCacheVersionConflictContext drRes, boolean sndToDht) { this.success = success; this.oldVal = oldVal; @@ -144,7 +144,7 @@ public long drExpireTime() { /** * @return DR conflict resolution context. */ - @Nullable public GridCacheVersionConflictContextImpl drResolveResult() { + @Nullable public GridCacheVersionConflictContext drResolveResult() { return drRes; } 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 4fc23a404c30c..03f20c6cd402e 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 @@ -18,12 +18,18 @@ package org.apache.ignite.internal.processors.cache; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; +import java.nio.*; + /** * Wrapped value bytes of cache entry. */ -public class GridCacheValueBytes { +public class GridCacheValueBytes extends MessageAdapter { + /** */ + private static final long serialVersionUID = 0L; + /** Null instance. */ private static final GridCacheValueBytes NULL = new GridCacheValueBytes(); @@ -113,6 +119,84 @@ public boolean isNull() { return bytes == null; } + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf) { + writer.setBuffer(buf); + + if (!typeWritten) { + if (!writer.writeByte(null, directType())) + return false; + + typeWritten = true; + } + + switch (state) { + case 0: + if (!writer.writeByteArray("bytes", bytes)) + return false; + + state++; + + case 1: + if (!writer.writeBoolean("plain", plain)) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf) { + reader.setBuffer(buf); + + switch (state) { + case 0: + bytes = reader.readByteArray("bytes"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 1: + plain = reader.readBoolean("plain"); + + if (!reader.isLastRead()) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public byte directType() { + return 88; + } + + /** {@inheritDoc} */ + @SuppressWarnings("CloneDoesntCallSuperClone") + @Override public MessageAdapter clone() { + GridCacheValueBytes _clone = new GridCacheValueBytes(); + + clone0(_clone); + + return _clone; + } + + /** {@inheritDoc} */ + @Override protected void clone0(MessageAdapter _msg) { + GridCacheValueBytes _clone = (GridCacheValueBytes)_msg; + + _clone.bytes = bytes; + _clone.plain = plain; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridCacheValueBytes.class, this, "len", bytes != null ? bytes.length : -1); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOsSerializationManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOsSerializationManager.java new file mode 100644 index 0000000000000..594f7914b8f94 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOsSerializationManager.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.internal.processors.cache.serialization.*; + +import java.util.*; + +/** + * Cache manager responsible for translating user objects into cache objects. + */ +public class IgniteCacheOsSerializationManager extends GridCacheManagerAdapter + implements IgniteCacheSerializationManager { + /** {@inheritDoc} */ + @Override public boolean portableEnabled() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean keepPortableInStore() { + return false; + } + + /** {@inheritDoc} */ + @Override public Object unwrapPortableIfNeeded(Object o, boolean keepPortable) { + return o; + } + + /** {@inheritDoc} */ + @Override public Collection unwrapPortablesIfNeeded(Collection col, boolean keepPortable) { + return col; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 73d2e17059a0b..a28eefdbc95e4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -248,8 +248,17 @@ public GridCacheContext context() { /** {@inheritDoc} */ @Override public Iterable> localEntries(CachePeekMode... peekModes) throws CacheException { - // TODO IGNITE-1. - throw new UnsupportedOperationException(); + GridCacheProjectionImpl prev = gate.enter(prj); + + try { + return delegate.localEntries(peekModes); + } + catch (IgniteCheckedException e) { + throw cacheException(e); + } + finally { + gate.leave(prev); + } } /** {@inheritDoc} */ @@ -298,14 +307,16 @@ public GridCacheContext context() { /** {@inheritDoc} */ @Override public int size(CachePeekMode... peekModes) throws CacheException { - // TODO IGNITE-1. - if (peekModes.length != 0) - throw new UnsupportedOperationException(); - GridCacheProjectionImpl prev = gate.enter(prj); try { - return ctx.cache().globalSize(); + if (isAsync()) { + setFuture(delegate.sizeAsync(peekModes)); + + return 0; + } + else + return delegate.size(peekModes); } catch (IgniteCheckedException e) { throw cacheException(e); @@ -317,11 +328,13 @@ public GridCacheContext context() { /** {@inheritDoc} */ @Override public int localSize(CachePeekMode... peekModes) { - // TODO IGNITE-1. GridCacheProjectionImpl prev = gate.enter(prj); try { - return delegate.size(); + return delegate.localSize(peekModes); + } + catch (IgniteCheckedException e) { + throw cacheException(e); } finally { gate.leave(prev); @@ -715,7 +728,10 @@ public Set> entrySetx(IgnitePredicate>... filter) { GridCacheProjectionImpl prev = gate.enter(prj); try { - delegate.removeAll(); + if (isAsync()) + setFuture(delegate.removeAllAsync()); + else + delegate.removeAll(); } catch (IgniteCheckedException e) { throw cacheException(e); @@ -727,11 +743,13 @@ public Set> entrySetx(IgnitePredicate>... filter) { /** {@inheritDoc} */ @Override public void clear() { - // TODO IGNITE-1. GridCacheProjectionImpl prev = gate.enter(prj); try { - delegate.clear(); + if (isAsync()) + setFuture(delegate.clearAsync()); + else + delegate.clear(); } catch (IgniteCheckedException e) { throw cacheException(e); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java index 53c933fd4956b..3b2d073f34bd6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java @@ -23,7 +23,6 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import org.jetbrains.annotations.*; import java.util.*; @@ -152,7 +151,7 @@ public GridCacheAffinityImpl(GridCacheContext cctx) { try { key = (K)cctx.marshalToPortable(key); } - catch (PortableException e) { + catch (IgniteException e) { U.error(log, "Failed to marshal key to portable: " + key, e); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java index 758b225c1f7a9..f20f2732a10b6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java @@ -19,9 +19,9 @@ import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -98,7 +98,7 @@ public int transactions() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCacheOptimisticCheckPreparedTxRequest _clone = new GridCacheOptimisticCheckPreparedTxRequest(); clone0(_clone); @@ -107,56 +107,56 @@ public int transactions() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCacheOptimisticCheckPreparedTxRequest _clone = (GridCacheOptimisticCheckPreparedTxRequest)_msg; _clone.futId = futId; _clone.miniId = miniId; - _clone.nearXidVer = nearXidVer; + _clone.nearXidVer = nearXidVer != null ? (GridCacheVersion)nearXidVer.clone() : null; _clone.txNum = txNum; } /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 9: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 10: - if (!commState.putCacheVersion(nearXidVer)) + if (!writer.writeMessage("nearXidVer", nearXidVer)) return false; - commState.idx++; + state++; case 11: - if (!commState.putInt(txNum)) + if (!writer.writeInt("txNum", txNum)) return false; - commState.idx++; + state++; } @@ -166,49 +166,43 @@ public int transactions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 9: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 10: - GridCacheVersion nearXidVer0 = commState.getCacheVersion(); + nearXidVer = reader.readMessage("nearXidVer"); - if (nearXidVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - nearXidVer = nearXidVer0; - - commState.idx++; + state++; case 11: - if (buf.remaining() < 4) - return false; + txNum = reader.readInt("txNum"); - txNum = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -217,7 +211,7 @@ public int transactions() { /** {@inheritDoc} */ @Override public byte directType() { - return 18; + return 16; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java index f26cdb7a8ab5a..7c9ae63e3273f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java @@ -18,9 +18,9 @@ package org.apache.ignite.internal.processors.cache.distributed; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -86,7 +86,7 @@ public boolean success() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCacheOptimisticCheckPreparedTxResponse _clone = new GridCacheOptimisticCheckPreparedTxResponse(); clone0(_clone); @@ -95,7 +95,7 @@ public boolean success() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCacheOptimisticCheckPreparedTxResponse _clone = (GridCacheOptimisticCheckPreparedTxResponse)_msg; @@ -108,36 +108,36 @@ public boolean success() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 9: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 10: - if (!commState.putBoolean(success)) + if (!writer.writeBoolean("success", success)) return false; - commState.idx++; + state++; } @@ -147,39 +147,35 @@ public boolean success() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 9: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 10: - if (buf.remaining() < 1) - return false; + success = reader.readBoolean("success"); - success = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -188,7 +184,7 @@ public boolean success() { /** {@inheritDoc} */ @Override public byte directType() { - return 19; + return 17; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java index f09297c93edbb..b4a6833fa06f6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java @@ -17,12 +17,11 @@ package org.apache.ignite.internal.processors.cache.distributed; -import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -52,7 +51,6 @@ public class GridCachePessimisticCheckCommittedTxRequest extends GridDistr private long originatingThreadId; /** Flag indicating that this is near-only check. */ - @GridDirectVersion(1) private boolean nearOnlyCheck; /** @@ -131,7 +129,7 @@ public boolean nearOnlyCheck() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCachePessimisticCheckCommittedTxRequest _clone = new GridCachePessimisticCheckCommittedTxRequest(); clone0(_clone); @@ -140,14 +138,14 @@ public boolean nearOnlyCheck() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCachePessimisticCheckCommittedTxRequest _clone = (GridCachePessimisticCheckCommittedTxRequest)_msg; _clone.futId = futId; _clone.miniId = miniId; - _clone.nearXidVer = nearXidVer; + _clone.nearXidVer = nearXidVer != null ? (GridCacheVersion)nearXidVer.clone() : null; _clone.originatingNodeId = originatingNodeId; _clone.originatingThreadId = originatingThreadId; _clone.nearOnlyCheck = nearOnlyCheck; @@ -156,54 +154,54 @@ public boolean nearOnlyCheck() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 9: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 10: - if (!commState.putCacheVersion(nearXidVer)) + if (!writer.writeBoolean("nearOnlyCheck", nearOnlyCheck)) return false; - commState.idx++; + state++; case 11: - if (!commState.putUuid(originatingNodeId)) + if (!writer.writeMessage("nearXidVer", nearXidVer)) return false; - commState.idx++; + state++; case 12: - if (!commState.putLong(originatingThreadId)) + if (!writer.writeUuid("originatingNodeId", originatingNodeId)) return false; - commState.idx++; + state++; case 13: - if (!commState.putBoolean(nearOnlyCheck)) + if (!writer.writeLong("originatingThreadId", originatingThreadId)) return false; - commState.idx++; + state++; } @@ -213,67 +211,59 @@ public boolean nearOnlyCheck() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 9: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 10: - GridCacheVersion nearXidVer0 = commState.getCacheVersion(); + nearOnlyCheck = reader.readBoolean("nearOnlyCheck"); - if (nearXidVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - nearXidVer = nearXidVer0; - - commState.idx++; + state++; case 11: - UUID originatingNodeId0 = commState.getUuid(); + nearXidVer = reader.readMessage("nearXidVer"); - if (originatingNodeId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - originatingNodeId = originatingNodeId0; - - commState.idx++; + state++; case 12: - if (buf.remaining() < 8) - return false; + originatingNodeId = reader.readUuid("originatingNodeId"); - originatingThreadId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 13: - if (buf.remaining() < 1) - return false; + originatingThreadId = reader.readLong("originatingThreadId"); - nearOnlyCheck = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -282,7 +272,7 @@ public boolean nearOnlyCheck() { /** {@inheritDoc} */ @Override public byte directType() { - return 20; + return 18; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java index cb40d3712aebf..36983beb66ff6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java @@ -21,9 +21,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -117,7 +117,7 @@ public GridCacheCommittedTxInfo committedTxInfo() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCachePessimisticCheckCommittedTxResponse _clone = new GridCachePessimisticCheckCommittedTxResponse(); clone0(_clone); @@ -126,7 +126,7 @@ public GridCacheCommittedTxInfo committedTxInfo() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCachePessimisticCheckCommittedTxResponse _clone = (GridCachePessimisticCheckCommittedTxResponse)_msg; @@ -140,36 +140,36 @@ public GridCacheCommittedTxInfo committedTxInfo() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (!commState.putByteArray(committedTxInfoBytes)) + if (!writer.writeByteArray("committedTxInfoBytes", committedTxInfoBytes)) return false; - commState.idx++; + state++; case 9: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 10: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; } @@ -179,41 +179,35 @@ public GridCacheCommittedTxInfo committedTxInfo() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - byte[] committedTxInfoBytes0 = commState.getByteArray(); + committedTxInfoBytes = reader.readByteArray("committedTxInfoBytes"); - if (committedTxInfoBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - committedTxInfoBytes = committedTxInfoBytes0; - - commState.idx++; + state++; case 9: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 10: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; } @@ -222,7 +216,7 @@ public GridCacheCommittedTxInfo committedTxInfo() { /** {@inheritDoc} */ @Override public byte directType() { - return 21; + return 19; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java index cd99351ac311d..00aae95698b66 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java @@ -21,9 +21,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.nio.*; import java.util.*; @@ -183,12 +183,12 @@ public List nearVersions() { /** {@inheritDoc} */ @Override public byte directType() { - return 82; + return 20; } /** {@inheritDoc} */ @SuppressWarnings("CloneDoesntCallSuperClone") - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCacheTtlUpdateRequest _clone = new GridCacheTtlUpdateRequest(); clone0(_clone); @@ -198,138 +198,54 @@ public List nearVersions() { /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (keysBytes != null) { - if (commState.it == null) { - if (!commState.putInt(keysBytes.size())) - return false; - - commState.it = keysBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("keysBytes", keysBytes, byte[].class)) + return false; - commState.idx++; + state++; case 4: - if (nearKeysBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearKeysBytes.size())) - return false; - - commState.it = nearKeysBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearKeysBytes", nearKeysBytes, byte[].class)) + return false; - commState.idx++; + state++; case 5: - if (nearVers != null) { - if (commState.it == null) { - if (!commState.putInt(nearVers.size())) - return false; - - commState.it = nearVers.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearVers", nearVers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 6: - if (!commState.putLong(topVer)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; case 7: - if (!commState.putLong(ttl)) + if (!writer.writeLong("ttl", ttl)) return false; - commState.idx++; + state++; case 8: - if (vers != null) { - if (commState.it == null) { - if (!commState.putInt(vers.size())) - return false; - - commState.it = vers.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("vers", vers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; } @@ -338,143 +254,59 @@ public List nearVersions() { /** {@inheritDoc} */ @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (keysBytes == null) - keysBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + keysBytes = reader.readCollection("keysBytes", byte[].class); - keysBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearKeysBytes == null) - nearKeysBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + nearKeysBytes = reader.readCollection("nearKeysBytes", byte[].class); - nearKeysBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearVers == null) - nearVers = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; + nearVers = reader.readCollection("nearVers", GridCacheVersion.class); - nearVers.add((GridCacheVersion)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 6: - if (buf.remaining() < 8) - return false; + topVer = reader.readLong("topVer"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - if (buf.remaining() < 8) - return false; + ttl = reader.readLong("ttl"); - ttl = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 8: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; + vers = reader.readCollection("vers", GridCacheVersion.class); - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (vers == null) - vers = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - vers.add((GridCacheVersion)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -482,7 +314,7 @@ public List nearVersions() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCacheTtlUpdateRequest _clone = (GridCacheTtlUpdateRequest)_msg; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java index 514fa51210111..4c7b959213913 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java @@ -21,9 +21,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -240,12 +240,12 @@ public int keysCount() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDistributedBaseMessage _clone = (GridDistributedBaseMessage)_msg; - _clone.ver = ver; + _clone.ver = ver != null ? (GridCacheVersion)ver.clone() : null; _clone.candsByIdx = candsByIdx; _clone.candsByIdxBytes = candsByIdxBytes; _clone.candsByKey = candsByKey; @@ -258,90 +258,48 @@ public int keysCount() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putByteArray(candsByIdxBytes)) + if (!writer.writeByteArray("candsByIdxBytes", candsByIdxBytes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(candsByKeyBytes)) + if (!writer.writeByteArray("candsByKeyBytes", candsByKeyBytes)) return false; - commState.idx++; + state++; case 5: - if (committedVers != null) { - if (commState.it == null) { - if (!commState.putInt(committedVers.size())) - return false; - - commState.it = committedVers.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("committedVers", committedVers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 6: - if (rolledbackVers != null) { - if (commState.it == null) { - if (!commState.putInt(rolledbackVers.size())) - return false; - - commState.it = rolledbackVers.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("rolledbackVers", rolledbackVers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 7: - if (!commState.putCacheVersion(ver)) + if (!writer.writeMessage("ver", ver)) return false; - commState.idx++; + state++; } @@ -351,99 +309,51 @@ public int keysCount() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - byte[] candsByIdxBytes0 = commState.getByteArray(); + candsByIdxBytes = reader.readByteArray("candsByIdxBytes"); - if (candsByIdxBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - candsByIdxBytes = candsByIdxBytes0; - - commState.idx++; + state++; case 4: - byte[] candsByKeyBytes0 = commState.getByteArray(); + candsByKeyBytes = reader.readByteArray("candsByKeyBytes"); - if (candsByKeyBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - candsByKeyBytes = candsByKeyBytes0; - - commState.idx++; + state++; case 5: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + committedVers = reader.readCollection("committedVers", GridCacheVersion.class); - if (commState.readSize >= 0) { - if (committedVers == null) - committedVers = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - committedVers.add((GridCacheVersion)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + rolledbackVers = reader.readCollection("rolledbackVers", GridCacheVersion.class); - if (commState.readSize >= 0) { - if (rolledbackVers == null) - rolledbackVers = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - rolledbackVers.add((GridCacheVersion)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - GridCacheVersion ver0 = commState.getCacheVersion(); + ver = reader.readMessage("ver"); - if (ver0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - ver = ver0; - - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java index cbc54ca58edaf..ad26d2ff6f2af 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java @@ -21,13 +21,13 @@ import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.cluster.*; -import org.apache.ignite.internal.compute.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.dht.*; import org.apache.ignite.internal.processors.cache.distributed.near.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.processors.task.*; +import org.apache.ignite.internal.util.future.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.resources.*; @@ -141,7 +141,7 @@ public void removeVersionedEntry(K key, GridCacheVersion ver) { do { topVer = ctx.affinity().affinityTopologyVersion(); - // Send job to all nodes. + // Send job to all data nodes. Collection nodes = ctx.grid().forDataNodes(name()).nodes(); if (!nodes.isEmpty()) { @@ -155,12 +155,61 @@ public void removeVersionedEntry(K key, GridCacheVersion ver) { if (log.isDebugEnabled()) log.debug("All remote nodes left while cache remove [cacheName=" + name() + "]"); } - catch (ComputeTaskTimeoutCheckedException e) { - U.warn(log, "Timed out waiting for remote nodes to finish cache remove (consider increasing " + - "'networkTimeout' configuration property) [cacheName=" + name() + "]"); + } + + /** {@inheritDoc} */ + @Override public IgniteInternalFuture removeAllAsync() { + GridFutureAdapter opFut = new GridFutureAdapter<>(ctx.kernalContext()); + + long topVer = ctx.affinity().affinityTopologyVersion(); + + removeAllAsync(opFut, topVer); + + return opFut; + } + + /** + * @param opFut Future. + * @param topVer Topology version. + */ + private void removeAllAsync(final GridFutureAdapter opFut, final long topVer) { + Collection nodes = ctx.grid().forDataNodes(name()).nodes(); + + if (!nodes.isEmpty()) { + IgniteInternalFuture rmvFut = ctx.closures().callAsyncNoFailover(BROADCAST, + new GlobalRemoveAllCallable<>(name(), topVer), nodes, true); + + rmvFut.listenAsync(new IgniteInClosure>() { + @Override public void apply(IgniteInternalFuture fut) { + try { + fut.get(); - throw e; + long topVer0 = ctx.affinity().affinityTopologyVersion(); + + if (topVer0 == topVer) + opFut.onDone(); + else + removeAllAsync(opFut, topVer0); + } + catch (ClusterGroupEmptyCheckedException ignore) { + if (log.isDebugEnabled()) + log.debug("All remote nodes left while cache remove [cacheName=" + name() + "]"); + + opFut.onDone(); + } + catch (IgniteCheckedException e) { + opFut.onDone(e); + } + catch (Error e) { + opFut.onDone(e); + + throw e; + } + } + }); } + else + opFut.onDone(); } /** {@inheritDoc} */ @@ -235,6 +284,16 @@ private GlobalRemoveAllCallable(String cacheName, long topVer) { } } } + + Iterator> it = dht.context().swap().offheapIterator(true, false, topVer); + + while (it.hasNext()) + dataLdr.removeData(it.next().getKey()); + + it = dht.context().swap().swapIterator(true, false, topVer); + + while (it.hasNext()) + dataLdr.removeData(it.next().getKey()); } } finally { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java index 2a1cb5d893586..1f77a01dd1736 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java @@ -22,10 +22,10 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; @@ -428,7 +428,7 @@ public GridCacheVersion[] drVersions() { /** {@inheritDoc} */ @SuppressWarnings({"CloneCallsConstructors", "OverriddenMethodCallDuringObjectConstruction", "CloneDoesntCallSuperClone"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDistributedLockRequest _clone = new GridDistributedLockRequest(); clone0(_clone); @@ -437,13 +437,13 @@ public GridCacheVersion[] drVersions() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDistributedLockRequest _clone = (GridDistributedLockRequest)_msg; _clone.nodeId = nodeId; - _clone.nearXidVer = nearXidVer; + _clone.nearXidVer = nearXidVer != null ? (GridCacheVersion)nearXidVer.clone() : null; _clone.threadId = threadId; _clone.futId = futId; _clone.timeout = timeout; @@ -467,156 +467,114 @@ public GridCacheVersion[] drVersions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (drVersByIdx != null) { - if (commState.it == null) { - if (!commState.putInt(drVersByIdx.length)) - return false; - - commState.it = arrayIterator(drVersByIdx); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeObjectArray("drVersByIdx", drVersByIdx, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 9: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 10: - if (!commState.putByteArray(grpLockKeyBytes)) + if (!writer.writeByteArray("grpLockKeyBytes", grpLockKeyBytes)) return false; - commState.idx++; + state++; case 11: - if (!commState.putBoolean(isInTx)) + if (!writer.writeBoolean("isInTx", isInTx)) return false; - commState.idx++; + state++; case 12: - if (!commState.putBoolean(isInvalidate)) + if (!writer.writeBoolean("isInvalidate", isInvalidate)) return false; - commState.idx++; + state++; case 13: - if (!commState.putBoolean(isRead)) + if (!writer.writeBoolean("isRead", isRead)) return false; - commState.idx++; + state++; case 14: - if (!commState.putEnum(isolation)) + if (!writer.writeEnum("isolation", isolation)) return false; - commState.idx++; + state++; case 15: - if (keyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(keyBytes.size())) - return false; - - commState.it = keyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("keyBytes", keyBytes, byte[].class)) + return false; - commState.idx++; + state++; case 16: - if (!commState.putCacheVersion(nearXidVer)) + if (!writer.writeMessage("nearXidVer", nearXidVer)) return false; - commState.idx++; + state++; case 17: - if (!commState.putUuid(nodeId)) + if (!writer.writeUuid("nodeId", nodeId)) return false; - commState.idx++; + state++; case 18: - if (!commState.putBoolean(partLock)) + if (!writer.writeBoolean("partLock", partLock)) return false; - commState.idx++; + state++; case 19: - if (!commState.putBooleanArray(retVals)) + if (!writer.writeBooleanArray("retVals", retVals)) return false; - commState.idx++; + state++; case 20: - if (!commState.putLong(threadId)) + if (!writer.writeLong("threadId", threadId)) return false; - commState.idx++; + state++; case 21: - if (!commState.putLong(timeout)) + if (!writer.writeLong("timeout", timeout)) return false; - commState.idx++; + state++; case 22: - if (!commState.putInt(txSize)) + if (!writer.writeInt("txSize", txSize)) return false; - commState.idx++; + state++; case 23: - if (!commState.putByteArray(writeEntriesBytes)) + if (!writer.writeByteArray("writeEntriesBytes", writeEntriesBytes)) return false; - commState.idx++; + state++; } @@ -626,195 +584,139 @@ public GridCacheVersion[] drVersions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + drVersByIdx = reader.readObjectArray("drVersByIdx", GridCacheVersion.class); - if (commState.readSize >= 0) { - if (drVersByIdx == null) - drVersByIdx = new GridCacheVersion[commState.readSize]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - drVersByIdx[i] = (GridCacheVersion)_val; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 9: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 10: - byte[] grpLockKeyBytes0 = commState.getByteArray(); + grpLockKeyBytes = reader.readByteArray("grpLockKeyBytes"); - if (grpLockKeyBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - grpLockKeyBytes = grpLockKeyBytes0; - - commState.idx++; + state++; case 11: - if (buf.remaining() < 1) - return false; + isInTx = reader.readBoolean("isInTx"); - isInTx = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 12: - if (buf.remaining() < 1) - return false; + isInvalidate = reader.readBoolean("isInvalidate"); - isInvalidate = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 13: - if (buf.remaining() < 1) - return false; + isRead = reader.readBoolean("isRead"); - isRead = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 14: - if (buf.remaining() < 1) - return false; + isolation = reader.readEnum("isolation", IgniteTxIsolation.class); - byte isolation0 = commState.getByte(); - - isolation = IgniteTxIsolation.fromOrdinal(isolation0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 15: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + keyBytes = reader.readCollection("keyBytes", byte[].class); - if (commState.readSize >= 0) { - if (keyBytes == null) - keyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - keyBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 16: - GridCacheVersion nearXidVer0 = commState.getCacheVersion(); + nearXidVer = reader.readMessage("nearXidVer"); - if (nearXidVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - nearXidVer = nearXidVer0; - - commState.idx++; + state++; case 17: - UUID nodeId0 = commState.getUuid(); + nodeId = reader.readUuid("nodeId"); - if (nodeId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - nodeId = nodeId0; - - commState.idx++; + state++; case 18: - if (buf.remaining() < 1) - return false; + partLock = reader.readBoolean("partLock"); - partLock = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 19: - boolean[] retVals0 = commState.getBooleanArray(); + retVals = reader.readBooleanArray("retVals"); - if (retVals0 == BOOLEAN_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - retVals = retVals0; - - commState.idx++; + state++; case 20: - if (buf.remaining() < 8) - return false; + threadId = reader.readLong("threadId"); - threadId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 21: - if (buf.remaining() < 8) - return false; + timeout = reader.readLong("timeout"); - timeout = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 22: - if (buf.remaining() < 4) - return false; + txSize = reader.readInt("txSize"); - txSize = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 23: - byte[] writeEntriesBytes0 = commState.getByteArray(); + writeEntriesBytes = reader.readByteArray("writeEntriesBytes"); - if (writeEntriesBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - writeEntriesBytes = writeEntriesBytes0; - - commState.idx++; + state++; } @@ -823,7 +725,7 @@ public GridCacheVersion[] drVersions() { /** {@inheritDoc} */ @Override public byte directType() { - return 22; + return 21; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockResponse.java index 0a791e204f05f..ae7ac0e2ad856 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockResponse.java @@ -21,11 +21,11 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -279,7 +279,7 @@ protected int valuesSize() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors", "OverriddenMethodCallDuringObjectConstruction"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDistributedLockResponse _clone = new GridDistributedLockResponse(); clone0(_clone); @@ -288,7 +288,7 @@ protected int valuesSize() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDistributedLockResponse _clone = (GridDistributedLockResponse)_msg; @@ -303,57 +303,36 @@ protected int valuesSize() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 9: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 10: - if (valBytes != null) { - if (commState.it == null) { - if (!commState.putInt(valBytes.size())) - return false; - - commState.it = valBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putValueBytes((GridCacheValueBytes)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("valBytes", valBytes, GridCacheValueBytes.class)) + return false; - commState.idx++; + state++; } @@ -363,60 +342,35 @@ protected int valuesSize() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 9: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 10: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; + valBytes = reader.readCollection("valBytes", GridCacheValueBytes.class); - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (valBytes == null) - valBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheValueBytes _val = commState.getValueBytes(); - - if (_val == VAL_BYTES_NOT_READ) - return false; - - valBytes.add((GridCacheValueBytes)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -425,7 +379,7 @@ protected int valuesSize() { /** {@inheritDoc} */ @Override public byte directType() { - return 23; + return 22; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java index 6a79fd5af50d6..d8cc29617db79 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java @@ -22,11 +22,11 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -346,7 +346,7 @@ public boolean groupLock() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors", "OverriddenMethodCallDuringObjectConstruction"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDistributedTxFinishRequest _clone = new GridDistributedTxFinishRequest(); clone0(_clone); @@ -355,17 +355,19 @@ public boolean groupLock() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDistributedTxFinishRequest _clone = (GridDistributedTxFinishRequest)_msg; _clone.futId = futId; _clone.threadId = threadId; - _clone.commitVer = commitVer; + _clone.commitVer = commitVer != null ? (GridCacheVersion)commitVer.clone() : null; _clone.invalidate = invalidate; _clone.commit = commit; - _clone.baseVer = baseVer; + _clone.syncCommit = syncCommit; + _clone.syncRollback = syncRollback; + _clone.baseVer = baseVer != null ? (GridCacheVersion)baseVer.clone() : null; _clone.writeEntries = writeEntries; _clone.writeEntriesBytes = writeEntriesBytes; _clone.recoveryWrites = recoveryWrites; @@ -379,138 +381,97 @@ public boolean groupLock() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (!commState.putCacheVersion(baseVer)) + if (!writer.writeMessage("baseVer", baseVer)) return false; - commState.idx++; + state++; case 9: - if (!commState.putBoolean(commit)) + if (!writer.writeBoolean("commit", commit)) return false; - commState.idx++; + state++; case 10: - if (!commState.putCacheVersion(commitVer)) + if (!writer.writeMessage("commitVer", commitVer)) return false; - commState.idx++; + state++; case 11: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 12: - if (!commState.putByteArray(grpLockKeyBytes)) + if (!writer.writeByteArray("grpLockKeyBytes", grpLockKeyBytes)) return false; - commState.idx++; + state++; case 13: - if (!commState.putBoolean(invalidate)) + if (!writer.writeBoolean("invalidate", invalidate)) return false; - commState.idx++; + state++; case 14: - if (!commState.putBoolean(syncCommit)) + if (!writer.writeCollection("recoveryWritesBytes", recoveryWritesBytes, byte[].class)) return false; - commState.idx++; + state++; case 15: - if (!commState.putBoolean(syncRollback)) + if (!writer.writeBoolean("syncCommit", syncCommit)) return false; - commState.idx++; + state++; case 16: - if (recoveryWritesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(recoveryWritesBytes.size())) - return false; - - commState.it = recoveryWritesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeBoolean("syncRollback", syncRollback)) + return false; - commState.idx++; + state++; case 17: - if (!commState.putLong(threadId)) + if (!writer.writeBoolean("sys", sys)) return false; - commState.idx++; + state++; case 18: - if (!commState.putInt(txSize)) + if (!writer.writeLong("threadId", threadId)) return false; - commState.idx++; + state++; case 19: - if (writeEntriesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(writeEntriesBytes.size())) - return false; - - commState.it = writeEntriesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeInt("txSize", txSize)) + return false; - commState.idx++; + state++; case 20: - if (!commState.putBoolean(sys)) + if (!writer.writeCollection("writeEntriesBytes", writeEntriesBytes, byte[].class)) return false; - commState.idx++; + state++; + } return true; @@ -519,165 +480,116 @@ public boolean groupLock() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - GridCacheVersion baseVer0 = commState.getCacheVersion(); + baseVer = reader.readMessage("baseVer"); - if (baseVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - baseVer = baseVer0; - - commState.idx++; + state++; case 9: - if (buf.remaining() < 1) - return false; + commit = reader.readBoolean("commit"); - commit = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 10: - GridCacheVersion commitVer0 = commState.getCacheVersion(); + commitVer = reader.readMessage("commitVer"); - if (commitVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - commitVer = commitVer0; - - commState.idx++; + state++; case 11: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 12: - byte[] grpLockKeyBytes0 = commState.getByteArray(); + grpLockKeyBytes = reader.readByteArray("grpLockKeyBytes"); - if (grpLockKeyBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - grpLockKeyBytes = grpLockKeyBytes0; - - commState.idx++; + state++; case 13: - if (buf.remaining() < 1) - return false; + invalidate = reader.readBoolean("invalidate"); - invalidate = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 14: - if (buf.remaining() < 1) - return false; + recoveryWritesBytes = reader.readCollection("recoveryWritesBytes", byte[].class); - syncCommit = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 15: - if (buf.remaining() < 1) - return false; + syncCommit = reader.readBoolean("syncCommit"); - syncRollback = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 16: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (recoveryWritesBytes == null) - recoveryWritesBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + syncRollback = reader.readBoolean("syncRollback"); - if (_val == BYTE_ARR_NOT_READ) - return false; - - recoveryWritesBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 17: - if (buf.remaining() < 8) - return false; + sys = reader.readBoolean("sys"); - threadId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 18: - if (buf.remaining() < 4) - return false; + threadId = reader.readLong("threadId"); - txSize = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 19: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (writeEntriesBytes == null) - writeEntriesBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + txSize = reader.readInt("txSize"); - if (_val == BYTE_ARR_NOT_READ) - return false; - - writeEntriesBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 20: - if (buf.remaining() < 1) + writeEntriesBytes = reader.readCollection("writeEntriesBytes", byte[].class); + + if (!reader.isLastRead()) return false; - sys = commState.getBoolean(); + state++; - commState.idx++; } return true; @@ -685,7 +597,7 @@ public boolean groupLock() { /** {@inheritDoc} */ @Override public byte directType() { - return 24; + return 23; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishResponse.java index c141c30a312fd..e31c24f2d5a79 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishResponse.java @@ -19,9 +19,9 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -76,7 +76,7 @@ public IgniteUuid futureId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors", "OverriddenMethodCallDuringObjectConstruction"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDistributedTxFinishResponse _clone = new GridDistributedTxFinishResponse(); clone0(_clone); @@ -85,42 +85,42 @@ public IgniteUuid futureId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDistributedTxFinishResponse _clone = (GridDistributedTxFinishResponse)_msg; - _clone.txId = txId; + _clone.txId = txId != null ? (GridCacheVersion)txId.clone() : null; _clone.futId = futId; } /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 4: - if (!commState.putCacheVersion(txId)) + if (!writer.writeMessage("txId", txId)) return false; - commState.idx++; + state++; } @@ -130,31 +130,27 @@ public IgniteUuid futureId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 4: - GridCacheVersion txId0 = commState.getCacheVersion(); + txId = reader.readMessage("txId"); - if (txId0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - txId = txId0; - - commState.idx++; + state++; } @@ -163,7 +159,7 @@ public IgniteUuid futureId() { /** {@inheritDoc} */ @Override public byte directType() { - return 25; + return 24; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java index 611fa70a15c8f..54d7757ae45a8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java @@ -22,9 +22,9 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; @@ -404,7 +404,7 @@ private void writeCollection(ObjectOutput out, Collection> c /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors", "OverriddenMethodCallDuringObjectConstruction"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDistributedTxPrepareRequest _clone = new GridDistributedTxPrepareRequest(); clone0(_clone); @@ -413,7 +413,7 @@ private void writeCollection(ObjectOutput out, Collection> c } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDistributedTxPrepareRequest _clone = (GridDistributedTxPrepareRequest)_msg; @@ -421,7 +421,7 @@ private void writeCollection(ObjectOutput out, Collection> c _clone.threadId = threadId; _clone.concurrency = concurrency; _clone.isolation = isolation; - _clone.commitVer = commitVer; + _clone.commitVer = commitVer != null ? (GridCacheVersion)commitVer.clone() : null; _clone.timeout = timeout; _clone.invalidate = invalidate; _clone.reads = reads; @@ -442,144 +442,103 @@ private void writeCollection(ObjectOutput out, Collection> c /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (!commState.putCacheVersion(commitVer)) + if (!writer.writeMessage("commitVer", commitVer)) return false; - commState.idx++; + state++; case 9: - if (!commState.putEnum(concurrency)) + if (!writer.writeEnum("concurrency", concurrency)) return false; - commState.idx++; + state++; case 10: - if (!commState.putByteArray(dhtVersBytes)) + if (!writer.writeByteArray("dhtVersBytes", dhtVersBytes)) return false; - commState.idx++; + state++; case 11: - if (!commState.putByteArray(grpLockKeyBytes)) + if (!writer.writeByteArray("grpLockKeyBytes", grpLockKeyBytes)) return false; - commState.idx++; + state++; case 12: - if (!commState.putBoolean(invalidate)) + if (!writer.writeBoolean("invalidate", invalidate)) return false; - commState.idx++; + state++; case 13: - if (!commState.putEnum(isolation)) + if (!writer.writeEnum("isolation", isolation)) return false; - commState.idx++; + state++; case 14: - if (!commState.putBoolean(partLock)) + if (!writer.writeBoolean("partLock", partLock)) return false; - commState.idx++; + state++; case 15: - if (readsBytes != null) { - if (commState.it == null) { - if (!commState.putInt(readsBytes.size())) - return false; - - commState.it = readsBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("readsBytes", readsBytes, byte[].class)) + return false; - commState.idx++; + state++; case 16: - if (!commState.putLong(threadId)) + if (!writer.writeBoolean("sys", sys)) return false; - commState.idx++; + state++; case 17: - if (!commState.putLong(timeout)) + if (!writer.writeLong("threadId", threadId)) return false; - commState.idx++; + state++; case 18: - if (!commState.putByteArray(txNodesBytes)) + if (!writer.writeLong("timeout", timeout)) return false; - commState.idx++; + state++; case 19: - if (!commState.putInt(txSize)) + if (!writer.writeByteArray("txNodesBytes", txNodesBytes)) return false; - commState.idx++; + state++; case 20: - if (writesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(writesBytes.size())) - return false; - - commState.it = writesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeInt("txSize", txSize)) + return false; - commState.idx++; + state++; case 21: - if (!commState.putBoolean(sys)) + if (!writer.writeCollection("writesBytes", writesBytes, byte[].class)) return false; - commState.idx++; + state++; + } return true; @@ -588,177 +547,124 @@ private void writeCollection(ObjectOutput out, Collection> c /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - GridCacheVersion commitVer0 = commState.getCacheVersion(); + commitVer = reader.readMessage("commitVer"); - if (commitVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - commitVer = commitVer0; - - commState.idx++; + state++; case 9: - if (buf.remaining() < 1) - return false; - - byte concurrency0 = commState.getByte(); + concurrency = reader.readEnum("concurrency", IgniteTxConcurrency.class); - concurrency = IgniteTxConcurrency.fromOrdinal(concurrency0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 10: - byte[] dhtVersBytes0 = commState.getByteArray(); + dhtVersBytes = reader.readByteArray("dhtVersBytes"); - if (dhtVersBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - dhtVersBytes = dhtVersBytes0; - - commState.idx++; + state++; case 11: - byte[] grpLockKeyBytes0 = commState.getByteArray(); + grpLockKeyBytes = reader.readByteArray("grpLockKeyBytes"); - if (grpLockKeyBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - grpLockKeyBytes = grpLockKeyBytes0; - - commState.idx++; + state++; case 12: - if (buf.remaining() < 1) - return false; + invalidate = reader.readBoolean("invalidate"); - invalidate = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 13: - if (buf.remaining() < 1) - return false; + isolation = reader.readEnum("isolation", IgniteTxIsolation.class); - byte isolation0 = commState.getByte(); - - isolation = IgniteTxIsolation.fromOrdinal(isolation0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 14: - if (buf.remaining() < 1) - return false; + partLock = reader.readBoolean("partLock"); - partLock = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 15: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (readsBytes == null) - readsBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - readsBytes.add((byte[])_val); + readsBytes = reader.readCollection("readsBytes", byte[].class); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 16: - if (buf.remaining() < 8) - return false; + sys = reader.readBoolean("sys"); - threadId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 17: - if (buf.remaining() < 8) - return false; + threadId = reader.readLong("threadId"); - timeout = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 18: - byte[] txNodesBytes0 = commState.getByteArray(); + timeout = reader.readLong("timeout"); - if (txNodesBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - txNodesBytes = txNodesBytes0; - - commState.idx++; + state++; case 19: - if (buf.remaining() < 4) - return false; + txNodesBytes = reader.readByteArray("txNodesBytes"); - txSize = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 20: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (writesBytes == null) - writesBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + txSize = reader.readInt("txSize"); - if (_val == BYTE_ARR_NOT_READ) - return false; - - writesBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 21: - if (buf.remaining() < 1) + writesBytes = reader.readCollection("writesBytes", byte[].class); + + if (!reader.isLastRead()) return false; - sys = commState.getBoolean(); + state++; - commState.idx++; } return true; @@ -766,7 +672,7 @@ private void writeCollection(ObjectOutput out, Collection> c /** {@inheritDoc} */ @Override public byte directType() { - return 26; + return 25; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareResponse.java index 837f8b0eac3b2..cd475133afc94 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareResponse.java @@ -21,9 +21,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -151,7 +151,7 @@ public void candidates(Map>> cands) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors", "OverriddenMethodCallDuringObjectConstruction"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDistributedTxPrepareResponse _clone = new GridDistributedTxPrepareResponse(); clone0(_clone); @@ -160,7 +160,7 @@ public void candidates(Map>> cands) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDistributedTxPrepareResponse _clone = (GridDistributedTxPrepareResponse)_msg; @@ -174,30 +174,30 @@ public void candidates(Map>> cands) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (!commState.putByteArray(candsBytes)) + if (!writer.writeByteArray("candsBytes", candsBytes)) return false; - commState.idx++; + state++; case 9: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; } @@ -207,31 +207,27 @@ public void candidates(Map>> cands) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - byte[] candsBytes0 = commState.getByteArray(); + candsBytes = reader.readByteArray("candsBytes"); - if (candsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - candsBytes = candsBytes0; - - commState.idx++; + state++; case 9: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; } @@ -240,7 +236,7 @@ public void candidates(Map>> cands) { /** {@inheritDoc} */ @Override public byte directType() { - return 27; + return 26; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java index 2f4789415a43e..906ab9eff93a5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java @@ -514,13 +514,13 @@ private void commitIfLocked() throws IgniteCheckedException { cacheCtx.conflictNeedResolve(cached.version(), explicitVer); if (drNeedResolve) { - IgniteBiTuple> + IgniteBiTuple> drRes = conflictResolve(op, txEntry.key(), val, valBytes, txEntry.ttl(), txEntry.drExpireTime(), explicitVer, cached); assert drRes != null; - GridCacheVersionConflictContextImpl drCtx = drRes.get2(); + GridCacheVersionConflictContext drCtx = drRes.get2(); if (drCtx.isUseOld()) op = NOOP; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java index 7dcabd19544ec..9c3f6abd61b4e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java @@ -20,9 +20,9 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -117,7 +117,7 @@ public void addKey(K key, byte[] bytes, GridCacheContext ctx) throws Ignit /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors", "OverriddenMethodCallDuringObjectConstruction"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDistributedUnlockRequest _clone = new GridDistributedUnlockRequest(); clone0(_clone); @@ -126,7 +126,7 @@ public void addKey(K key, byte[] bytes, GridCacheContext ctx) throws Ignit } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDistributedUnlockRequest _clone = (GridDistributedUnlockRequest)_msg; @@ -138,45 +138,24 @@ public void addKey(K key, byte[] bytes, GridCacheContext ctx) throws Ignit /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 8: - if (keyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(keyBytes.size())) - return false; + if (!writer.writeCollection("keyBytes", keyBytes, byte[].class)) + return false; - commState.it = keyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } - - commState.idx++; + state++; } @@ -186,40 +165,19 @@ public void addKey(K key, byte[] bytes, GridCacheContext ctx) throws Ignit /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 8: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (keyBytes == null) - keyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - keyBytes.add((byte[])_val); - - commState.readItems++; - } - } + keyBytes = reader.readCollection("keyBytes", byte[].class); - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -228,7 +186,7 @@ public void addKey(K key, byte[] bytes, GridCacheContext ctx) throws Ignit /** {@inheritDoc} */ @Override public byte directType() { - return 28; + return 27; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentRequest.java index 4fffd45a6196f..3534fd30b37d2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentRequest.java @@ -18,8 +18,8 @@ package org.apache.ignite.internal.processors.cache.distributed.dht; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.nio.*; @@ -63,12 +63,12 @@ public GridDhtAffinityAssignmentRequest(int cacheId, long topVer) { /** {@inheritDoc} */ @Override public byte directType() { - return 79; + return 28; } /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtAffinityAssignmentRequest _clone = new GridDhtAffinityAssignmentRequest(); clone0(_clone); @@ -77,7 +77,7 @@ public GridDhtAffinityAssignmentRequest(int cacheId, long topVer) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtAffinityAssignmentRequest _clone = (GridDhtAffinityAssignmentRequest)_msg; @@ -87,24 +87,24 @@ public GridDhtAffinityAssignmentRequest(int cacheId, long topVer) { /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putLong(topVer)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; } @@ -113,19 +113,19 @@ public GridDhtAffinityAssignmentRequest(int cacheId, long topVer) { /** {@inheritDoc} */ @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (buf.remaining() < 8) - return false; + topVer = reader.readLong("topVer"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java index 226bd005d0921..4a44303cedf00 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java @@ -21,9 +21,9 @@ import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.nio.*; import java.util.*; @@ -85,12 +85,12 @@ public List> affinityAssignment() { /** {@inheritDoc} */ @Override public byte directType() { - return 80; + return 29; } /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtAffinityAssignmentResponse _clone = new GridDhtAffinityAssignmentResponse(); clone0(_clone); @@ -99,7 +99,7 @@ public List> affinityAssignment() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtAffinityAssignmentResponse _clone = (GridDhtAffinityAssignmentResponse)_msg; @@ -128,30 +128,30 @@ public List> affinityAssignment() { /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putByteArray(affAssignmentBytes)) + if (!writer.writeByteArray("affAssignmentBytes", affAssignmentBytes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putLong(topVer)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; } @@ -160,29 +160,27 @@ public List> affinityAssignment() { /** {@inheritDoc} */ @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - byte[] affAssignmentBytes0 = commState.getByteArray(); + affAssignmentBytes = reader.readByteArray("affAssignmentBytes"); - if (affAssignmentBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - affAssignmentBytes = affAssignmentBytes0; - - commState.idx++; + state++; case 4: - if (buf.remaining() < 8) - return false; + topVer = reader.readLong("topVer"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java index 7885a38438d1e..483016d6e336c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java @@ -721,7 +721,7 @@ public void sendTtlUpdateRequest(@Nullable final IgniteCacheExpiryPolicy expiryP ctx.io().send(req.getKey(), req.getValue()); } catch (IgniteCheckedException e) { - log.error("Failed to send TTL update request.", e); + U.error(log, "Failed to send TTL update request.", e); } } } @@ -912,6 +912,83 @@ private PartitionEntrySet(int partId) { } } + /** + * @param primary If {@code true} includes primary entries. + * @param backup If {@code true} includes backup entries. + * @return Local entries iterator. + */ + public Iterator> localEntriesIterator(final boolean primary, final boolean backup) { + assert primary || backup; + + if (primary && backup) + return iterator(map.entries0().iterator(), !ctx.keepPortable()); + else { + final long topVer = ctx.affinity().affinityTopologyVersion(); + + final Iterator> partIt = topology().currentLocalPartitions().iterator(); + + Iterator> it = new Iterator>() { + private GridCacheEntryEx next; + + private Iterator> curIt; + + { + advance(); + } + + @Override public boolean hasNext() { + return next != null; + } + + @Override public GridCacheEntryEx next() { + if (next == null) + throw new NoSuchElementException(); + + GridCacheEntryEx e = next; + + advance(); + + return e; + } + + @Override public void remove() { + throw new UnsupportedOperationException(); + } + + private void advance() { + next = null; + + do { + if (curIt == null) { + while (partIt.hasNext()) { + GridDhtLocalPartition part = partIt.next(); + + if (primary == part.primary(topVer)) { + curIt = part.entries().iterator(); + + break; + } + } + } + + if (curIt != null) { + if (curIt.hasNext()) { + next = curIt.next(); + + break; + } + else + curIt = null; + } + } + while (partIt.hasNext()); + } + }; + + return iterator(it, !ctx.keepPortable()); + } + } + /** * Complex partition iterator for both partition and swap iteration. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java index 0c2fb2d491b60..763cec0708401 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java @@ -1136,7 +1136,7 @@ void onResult(GridDhtLockResponse res) { evictReaders(cctx, res.nearEvicted(), node.id(), res.messageId(), nearMapping); } - Set invalidParts = res.invalidPartitions(); + Collection invalidParts = res.invalidPartitions(); // Removing mappings for invalid partitions. if (!F.isEmpty(invalidParts)) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java index a6a48b89495ef..a9a93f764b87c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java @@ -24,11 +24,11 @@ import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; @@ -71,15 +71,12 @@ public class GridDhtLockRequest extends GridDistributedLockRequest { private long topVer; /** Subject ID. */ - @GridDirectVersion(1) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(2) private int taskNameHash; /** Indexes of keys needed to be preloaded. */ - @GridDirectVersion(3) private BitSet preloadKeys; /** TTL for read operation. */ @@ -345,7 +342,7 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtLockRequest _clone = new GridDhtLockRequest(); clone0(_clone); @@ -354,7 +351,7 @@ public long accessTtl() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtLockRequest _clone = (GridDhtLockRequest)_msg; @@ -375,93 +372,72 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 24: - if (!commState.putBitSet(invalidateEntries)) + if (!writer.writeLong("accessTtl", accessTtl)) return false; - commState.idx++; + state++; case 25: - if (!commState.putGridUuid(miniId)) + if (!writer.writeBitSet("invalidateEntries", invalidateEntries)) return false; - commState.idx++; + state++; case 26: - if (nearKeyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearKeyBytes.size())) - return false; - - commState.it = nearKeyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeIgniteUuid("miniId", miniId)) + return false; - commState.idx++; + state++; case 27: - if (!commState.putByteArray(ownedBytes)) + if (!writer.writeCollection("nearKeyBytes", nearKeyBytes, byte[].class)) return false; - commState.idx++; + state++; case 28: - if (!commState.putLong(topVer)) + if (!writer.writeByteArray("ownedBytes", ownedBytes)) return false; - commState.idx++; + state++; case 29: - if (!commState.putUuid(subjId)) + if (!writer.writeBitSet("preloadKeys", preloadKeys)) return false; - commState.idx++; + state++; case 30: - if (!commState.putInt(taskNameHash)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 31: - if (!commState.putBitSet(preloadKeys)) + if (!writer.writeInt("taskNameHash", taskNameHash)) return false; - commState.idx++; + state++; case 32: - if (!commState.putLong(accessTtl)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; } @@ -471,114 +447,84 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 24: - BitSet invalidateEntries0 = commState.getBitSet(); + accessTtl = reader.readLong("accessTtl"); - if (invalidateEntries0 == BIT_SET_NOT_READ) + if (!reader.isLastRead()) return false; - invalidateEntries = invalidateEntries0; - - commState.idx++; + state++; case 25: - IgniteUuid miniId0 = commState.getGridUuid(); + invalidateEntries = reader.readBitSet("invalidateEntries"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 26: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearKeyBytes == null) - nearKeyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + miniId = reader.readIgniteUuid("miniId"); - nearKeyBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 27: - byte[] ownedBytes0 = commState.getByteArray(); + nearKeyBytes = reader.readCollection("nearKeyBytes", byte[].class); - if (ownedBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - ownedBytes = ownedBytes0; - - commState.idx++; + state++; case 28: - if (buf.remaining() < 8) - return false; + ownedBytes = reader.readByteArray("ownedBytes"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 29: - UUID subjId0 = commState.getUuid(); + preloadKeys = reader.readBitSet("preloadKeys"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 30: - if (buf.remaining() < 4) - return false; + subjId = reader.readUuid("subjId"); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 31: - BitSet preloadKeys0 = commState.getBitSet(); + taskNameHash = reader.readInt("taskNameHash"); - if (preloadKeys0 == BIT_SET_NOT_READ) + if (!reader.isLastRead()) return false; - preloadKeys = preloadKeys0; - - commState.idx++; + state++; case 32: - if (buf.remaining() < 8) + topVer = reader.readLong("topVer"); + + if (!reader.isLastRead()) return false; - accessTtl = commState.getLong(); + state++; - commState.idx++; } return true; @@ -586,7 +532,7 @@ public long accessTtl() { /** {@inheritDoc} */ @Override public byte directType() { - return 29; + return 30; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java index d472b341d90ef..48ef34d84c964 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java @@ -24,10 +24,10 @@ import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -55,7 +55,7 @@ public class GridDhtLockResponse extends GridDistributedLockResponse /** Invalid partitions. */ @GridToStringInclude @GridDirectCollection(int.class) - private Set invalidParts = new GridLeanSet<>(); + private Collection invalidParts = new GridLeanSet<>(); @GridDirectTransient /** Preload entries. */ @@ -63,7 +63,6 @@ public class GridDhtLockResponse extends GridDistributedLockResponse /** */ @GridDirectCollection(byte[].class) - @GridDirectVersion(1) private List preloadEntriesBytes; /** @@ -139,7 +138,7 @@ public void addInvalidPartition(int part) { /** * @return Invalid partitions. */ - public Set invalidPartitions() { + public Collection invalidPartitions() { return invalidParts; } @@ -201,7 +200,7 @@ public Collection> preloadEntries() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtLockResponse _clone = new GridDhtLockResponse(); clone0(_clone); @@ -210,7 +209,7 @@ public Collection> preloadEntries() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtLockResponse _clone = (GridDhtLockResponse)_msg; @@ -226,105 +225,42 @@ public Collection> preloadEntries() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 11: - if (invalidParts != null) { - if (commState.it == null) { - if (!commState.putInt(invalidParts.size())) - return false; - - commState.it = invalidParts.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("invalidParts", invalidParts, int.class)) + return false; - commState.idx++; + state++; case 12: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 13: - if (nearEvictedBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearEvictedBytes.size())) - return false; - - commState.it = nearEvictedBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearEvictedBytes", nearEvictedBytes, byte[].class)) + return false; - commState.idx++; + state++; case 14: - if (preloadEntriesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(preloadEntriesBytes.size())) - return false; - - commState.it = preloadEntriesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("preloadEntriesBytes", preloadEntriesBytes, byte[].class)) + return false; - commState.idx++; + state++; } @@ -334,108 +270,43 @@ public Collection> preloadEntries() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 11: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (invalidParts == null) - invalidParts = new HashSet<>(commState.readSize); + invalidParts = reader.readCollection("invalidParts", int.class); - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; - - int _val = commState.getInt(); - - invalidParts.add((Integer)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 12: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 13: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearEvictedBytes == null) - nearEvictedBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + nearEvictedBytes = reader.readCollection("nearEvictedBytes", byte[].class); - nearEvictedBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 14: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (preloadEntriesBytes == null) - preloadEntriesBytes = new ArrayList<>(commState.readSize); + preloadEntriesBytes = reader.readCollection("preloadEntriesBytes", byte[].class); - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - preloadEntriesBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -444,7 +315,7 @@ public Collection> preloadEntries() { /** {@inheritDoc} */ @Override public byte directType() { - return 30; + return 31; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java index b7a35164bdfb5..9bdf4bdce9825 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java @@ -24,10 +24,10 @@ import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; @@ -78,11 +78,9 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest private GridCacheVersion writeVer; /** Subject ID. */ - @GridDirectVersion(1) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(2) private int taskNameHash; /** TTLs for optimistic transaction. */ @@ -351,7 +349,7 @@ public GridLongList nearTtls() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtTxFinishRequest _clone = new GridDhtTxFinishRequest(); clone0(_clone); @@ -360,7 +358,7 @@ public GridLongList nearTtls() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtTxFinishRequest _clone = (GridDhtTxFinishRequest)_msg; @@ -374,148 +372,106 @@ public GridLongList nearTtls() { _clone.topVer = topVer; _clone.pendingVers = pendingVers; _clone.onePhaseCommit = onePhaseCommit; - _clone.writeVer = writeVer; + _clone.writeVer = writeVer != null ? (GridCacheVersion)writeVer.clone() : null; _clone.subjId = subjId; _clone.taskNameHash = taskNameHash; - _clone.ttls = ttls; - _clone.nearTtls = nearTtls; + _clone.ttls = ttls != null ? (GridLongList)ttls.clone() : null; + _clone.nearTtls = nearTtls != null ? (GridLongList)nearTtls.clone() : null; } /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 21: - if (!commState.putEnum(isolation)) + if (!writer.writeEnum("isolation", isolation)) return false; - commState.idx++; + state++; case 22: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 23: - if (!commState.putUuid(nearNodeId)) + if (!writer.writeUuid("nearNodeId", nearNodeId)) return false; - commState.idx++; + state++; case 24: - if (nearWritesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearWritesBytes.size())) - return false; - - commState.it = nearWritesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMessage("nearTtls", nearTtls)) + return false; - commState.idx++; + state++; case 25: - if (!commState.putBoolean(onePhaseCommit)) + if (!writer.writeCollection("nearWritesBytes", nearWritesBytes, byte[].class)) return false; - commState.idx++; + state++; case 26: - if (pendingVers != null) { - if (commState.it == null) { - if (!commState.putInt(pendingVers.size())) - return false; - - commState.it = pendingVers.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeBoolean("onePhaseCommit", onePhaseCommit)) + return false; - commState.idx++; + state++; case 27: - if (!commState.putBoolean(sysInvalidate)) + if (!writer.writeCollection("pendingVers", pendingVers, GridCacheVersion.class)) return false; - commState.idx++; + state++; case 28: - if (!commState.putLong(topVer)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 29: - if (!commState.putCacheVersion(writeVer)) + if (!writer.writeBoolean("sysInvalidate", sysInvalidate)) return false; - commState.idx++; + state++; case 30: - if (!commState.putUuid(subjId)) + if (!writer.writeInt("taskNameHash", taskNameHash)) return false; - commState.idx++; + state++; case 31: - if (!commState.putInt(taskNameHash)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; case 32: - if (!commState.putLongList(ttls)) + if (!writer.writeMessage("ttls", ttls)) return false; - commState.idx++; + state++; case 33: - if (!commState.putLongList(nearTtls)) + if (!writer.writeMessage("writeVer", writeVer)) return false; - commState.idx++; + state++; } @@ -525,171 +481,115 @@ public GridLongList nearTtls() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 21: - if (buf.remaining() < 1) - return false; - - byte isolation0 = commState.getByte(); + isolation = reader.readEnum("isolation", IgniteTxIsolation.class); - isolation = IgniteTxIsolation.fromOrdinal(isolation0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 22: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 23: - UUID nearNodeId0 = commState.getUuid(); + nearNodeId = reader.readUuid("nearNodeId"); - if (nearNodeId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - nearNodeId = nearNodeId0; - - commState.idx++; + state++; case 24: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearWritesBytes == null) - nearWritesBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - nearWritesBytes.add((byte[])_val); + nearTtls = reader.readMessage("nearTtls"); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 25: - if (buf.remaining() < 1) - return false; + nearWritesBytes = reader.readCollection("nearWritesBytes", byte[].class); - onePhaseCommit = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 26: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (pendingVers == null) - pendingVers = new ArrayList<>(commState.readSize); + onePhaseCommit = reader.readBoolean("onePhaseCommit"); - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - pendingVers.add((GridCacheVersion)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 27: - if (buf.remaining() < 1) - return false; + pendingVers = reader.readCollection("pendingVers", GridCacheVersion.class); - sysInvalidate = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 28: - if (buf.remaining() < 8) - return false; + subjId = reader.readUuid("subjId"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 29: - GridCacheVersion writeVer0 = commState.getCacheVersion(); + sysInvalidate = reader.readBoolean("sysInvalidate"); - if (writeVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - writeVer = writeVer0; - - commState.idx++; + state++; case 30: - UUID subjId0 = commState.getUuid(); + taskNameHash = reader.readInt("taskNameHash"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 31: - if (buf.remaining() < 4) - return false; + topVer = reader.readLong("topVer"); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 32: - GridLongList ttls0 = commState.getLongList(); + ttls = reader.readMessage("ttls"); - if (ttls0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - ttls = ttls0; - - commState.idx++; + state++; case 33: - GridLongList nearTtls0 = commState.getLongList(); + writeVer = reader.readMessage("writeVer"); - if (nearTtls0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - nearTtls = nearTtls0; - - commState.idx++; + state++; } @@ -698,6 +598,6 @@ public GridLongList nearTtls() { /** {@inheritDoc} */ @Override public byte directType() { - return 31; + return 32; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java index 121a19b0379f3..c8b2046a9cd69 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java @@ -19,9 +19,9 @@ import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -70,7 +70,7 @@ public IgniteUuid miniId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtTxFinishResponse _clone = new GridDhtTxFinishResponse(); clone0(_clone); @@ -79,7 +79,7 @@ public IgniteUuid miniId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtTxFinishResponse _clone = (GridDhtTxFinishResponse)_msg; @@ -90,24 +90,24 @@ public IgniteUuid miniId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 5: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; } @@ -117,21 +117,19 @@ public IgniteUuid miniId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 5: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; } @@ -140,6 +138,6 @@ public IgniteUuid miniId() { /** {@inheritDoc} */ @Override public byte directType() { - return 32; + return 33; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java index 3159c5e7260aa..92078f63ba439 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java @@ -24,10 +24,10 @@ import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -80,14 +80,11 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareReque private boolean last; /** Subject ID. */ - @GridDirectVersion(1) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(2) private int taskNameHash; - @GridDirectVersion(3) /** Preload keys. */ private BitSet preloadKeys; @@ -316,7 +313,7 @@ public Map, GridCacheVersion> owned() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtTxPrepareRequest _clone = new GridDhtTxPrepareRequest(); clone0(_clone); @@ -325,7 +322,7 @@ public Map, GridCacheVersion> owned() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtTxPrepareRequest _clone = (GridDhtTxPrepareRequest)_msg; @@ -339,7 +336,7 @@ public Map, GridCacheVersion> owned() { _clone.nearWritesBytes = nearWritesBytes; _clone.owned = owned; _clone.ownedBytes = ownedBytes; - _clone.nearXidVer = nearXidVer; + _clone.nearXidVer = nearXidVer != null ? (GridCacheVersion)nearXidVer.clone() : null; _clone.last = last; _clone.subjId = subjId; _clone.taskNameHash = taskNameHash; @@ -349,111 +346,90 @@ public Map, GridCacheVersion> owned() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 22: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 23: - if (!commState.putBitSet(invalidateNearEntries)) + if (!writer.writeBitSet("invalidateNearEntries", invalidateNearEntries)) return false; - commState.idx++; + state++; case 24: - if (!commState.putBoolean(last)) + if (!writer.writeBoolean("last", last)) return false; - commState.idx++; + state++; case 25: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 26: - if (!commState.putUuid(nearNodeId)) + if (!writer.writeUuid("nearNodeId", nearNodeId)) return false; - commState.idx++; + state++; case 27: - if (nearWritesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearWritesBytes.size())) - return false; - - commState.it = nearWritesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearWritesBytes", nearWritesBytes, byte[].class)) + return false; - commState.idx++; + state++; case 28: - if (!commState.putCacheVersion(nearXidVer)) + if (!writer.writeMessage("nearXidVer", nearXidVer)) return false; - commState.idx++; + state++; case 29: - if (!commState.putByteArray(ownedBytes)) + if (!writer.writeByteArray("ownedBytes", ownedBytes)) return false; - commState.idx++; + state++; case 30: - if (!commState.putLong(topVer)) + if (!writer.writeBitSet("preloadKeys", preloadKeys)) return false; - commState.idx++; + state++; case 31: - if (!commState.putUuid(subjId)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 32: - if (!commState.putInt(taskNameHash)) + if (!writer.writeInt("taskNameHash", taskNameHash)) return false; - commState.idx++; + state++; case 33: - if (!commState.putBitSet(preloadKeys)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; } @@ -463,144 +439,107 @@ public Map, GridCacheVersion> owned() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 22: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 23: - BitSet invalidateNearEntries0 = commState.getBitSet(); + invalidateNearEntries = reader.readBitSet("invalidateNearEntries"); - if (invalidateNearEntries0 == BIT_SET_NOT_READ) + if (!reader.isLastRead()) return false; - invalidateNearEntries = invalidateNearEntries0; - - commState.idx++; + state++; case 24: - if (buf.remaining() < 1) - return false; + last = reader.readBoolean("last"); - last = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 25: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 26: - UUID nearNodeId0 = commState.getUuid(); + nearNodeId = reader.readUuid("nearNodeId"); - if (nearNodeId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - nearNodeId = nearNodeId0; - - commState.idx++; + state++; case 27: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearWritesBytes == null) - nearWritesBytes = new ArrayList<>(commState.readSize); + nearWritesBytes = reader.readCollection("nearWritesBytes", byte[].class); - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - nearWritesBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 28: - GridCacheVersion nearXidVer0 = commState.getCacheVersion(); + nearXidVer = reader.readMessage("nearXidVer"); - if (nearXidVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - nearXidVer = nearXidVer0; - - commState.idx++; + state++; case 29: - byte[] ownedBytes0 = commState.getByteArray(); + ownedBytes = reader.readByteArray("ownedBytes"); - if (ownedBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - ownedBytes = ownedBytes0; - - commState.idx++; + state++; case 30: - if (buf.remaining() < 8) - return false; + preloadKeys = reader.readBitSet("preloadKeys"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 31: - UUID subjId0 = commState.getUuid(); + subjId = reader.readUuid("subjId"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 32: - if (buf.remaining() < 4) - return false; + taskNameHash = reader.readInt("taskNameHash"); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 33: - BitSet preloadKeys0 = commState.getBitSet(); + topVer = reader.readLong("topVer"); - if (preloadKeys0 == BIT_SET_NOT_READ) + if (!reader.isLastRead()) return false; - preloadKeys = preloadKeys0; - - commState.idx++; + state++; } @@ -609,6 +548,6 @@ public Map, GridCacheVersion> owned() { /** {@inheritDoc} */ @Override public byte directType() { - return 33; + return 34; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java index 2a3501b27a2e0..319639949e2a3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java @@ -23,10 +23,10 @@ import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -65,7 +65,6 @@ public class GridDhtTxPrepareResponse extends GridDistributedTxPrepareResp /** */ @GridDirectCollection(byte[].class) - @GridDirectVersion(1) private List preloadEntriesBytes; /** @@ -207,7 +206,7 @@ public void addPreloadEntry(GridCacheEntryInfo info) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtTxPrepareResponse _clone = new GridDhtTxPrepareResponse(); clone0(_clone); @@ -216,7 +215,7 @@ public void addPreloadEntry(GridCacheEntryInfo info) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtTxPrepareResponse _clone = (GridDhtTxPrepareResponse)_msg; @@ -233,111 +232,48 @@ public void addPreloadEntry(GridCacheEntryInfo info) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 10: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 11: - if (invalidParts != null) { - if (commState.it == null) { - if (!commState.putInt(invalidParts.size())) - return false; - - commState.it = invalidParts.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("invalidParts", invalidParts, int.class)) + return false; - commState.idx++; + state++; case 12: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 13: - if (nearEvictedBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearEvictedBytes.size())) - return false; - - commState.it = nearEvictedBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearEvictedBytes", nearEvictedBytes, byte[].class)) + return false; - commState.idx++; + state++; case 14: - if (preloadEntriesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(preloadEntriesBytes.size())) - return false; - - commState.it = preloadEntriesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("preloadEntriesBytes", preloadEntriesBytes, byte[].class)) + return false; - commState.idx++; + state++; } @@ -347,118 +283,51 @@ public void addPreloadEntry(GridCacheEntryInfo info) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 10: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 11: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (invalidParts == null) - invalidParts = new ArrayList<>(commState.readSize); + invalidParts = reader.readCollection("invalidParts", int.class); - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; - - int _val = commState.getInt(); - - invalidParts.add((Integer)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 12: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 13: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearEvictedBytes == null) - nearEvictedBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + nearEvictedBytes = reader.readCollection("nearEvictedBytes", byte[].class); - nearEvictedBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 14: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (preloadEntriesBytes == null) - preloadEntriesBytes = new ArrayList<>(commState.readSize); + preloadEntriesBytes = reader.readCollection("preloadEntriesBytes", byte[].class); - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - preloadEntriesBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -467,6 +336,6 @@ public void addPreloadEntry(GridCacheEntryInfo info) { /** {@inheritDoc} */ @Override public byte directType() { - return 34; + return 35; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java index 8750376877c09..7c381d6b37e83 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java @@ -21,8 +21,8 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -105,7 +105,7 @@ public void addNearKey(K key, byte[] keyBytes, GridCacheSharedContext ctx) /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtUnlockRequest _clone = new GridDhtUnlockRequest(); clone0(_clone); @@ -114,7 +114,7 @@ public void addNearKey(K key, byte[] keyBytes, GridCacheSharedContext ctx) } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtUnlockRequest _clone = (GridDhtUnlockRequest)_msg; @@ -126,45 +126,24 @@ public void addNearKey(K key, byte[] keyBytes, GridCacheSharedContext ctx) /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 9: - if (nearKeyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearKeyBytes.size())) - return false; + if (!writer.writeCollection("nearKeyBytes", nearKeyBytes, byte[].class)) + return false; - commState.it = nearKeyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } - - commState.idx++; + state++; } @@ -174,40 +153,19 @@ public void addNearKey(K key, byte[] keyBytes, GridCacheSharedContext ctx) /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 9: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearKeyBytes == null) - nearKeyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - nearKeyBytes.add((byte[])_val); - - commState.readItems++; - } - } + nearKeyBytes = reader.readCollection("nearKeyBytes", byte[].class); - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -216,6 +174,6 @@ public void addNearKey(K key, byte[] keyBytes, GridCacheSharedContext ctx) /** {@inheritDoc} */ @Override public byte directType() { - return 35; + return 36; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index 6921c5b6d1fc8..21157f3ea0b8d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -1708,7 +1708,7 @@ primary && writeThrough(), if (dhtFut != null) { if (updRes.sendToDht()) { // Send to backups even in case of remove-remove scenarios. - GridCacheVersionConflictContextImpl ctx = updRes.drResolveResult(); + GridCacheVersionConflictContext ctx = updRes.drResolveResult(); long ttl = updRes.newTtl(); long expireTime = updRes.drExpireTime(); @@ -1754,7 +1754,7 @@ else if (ctx.isMerge()) { if (hasNear) { if (primary && updRes.sendToDht()) { if (!ctx.affinity().belongs(node, entry.partition(), topVer)) { - GridCacheVersionConflictContextImpl ctx = updRes.drResolveResult(); + GridCacheVersionConflictContext ctx = updRes.drResolveResult(); long ttl = updRes.newTtl(); long expireTime = updRes.drExpireTime(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java index 44a8857cba28e..955bb4f55ba45 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java @@ -20,8 +20,8 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -74,7 +74,7 @@ public Collection futureVersions() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtAtomicDeferredUpdateResponse _clone = new GridDhtAtomicDeferredUpdateResponse(); clone0(_clone); @@ -83,7 +83,7 @@ public Collection futureVersions() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtAtomicDeferredUpdateResponse _clone = (GridDhtAtomicDeferredUpdateResponse)_msg; @@ -94,45 +94,24 @@ public Collection futureVersions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (futVers != null) { - if (commState.it == null) { - if (!commState.putInt(futVers.size())) - return false; + if (!writer.writeCollection("futVers", futVers, GridCacheVersion.class)) + return false; - commState.it = futVers.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } - - commState.idx++; + state++; } @@ -142,40 +121,19 @@ public Collection futureVersions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (futVers == null) - futVers = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - futVers.add((GridCacheVersion)_val); - - commState.readItems++; - } - } + futVers = reader.readCollection("futVers", GridCacheVersion.class); - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -184,6 +142,6 @@ public Collection futureVersions() { /** {@inheritDoc} */ @Override public byte directType() { - return 36; + return 37; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java index 3b538c0517169..7672f6c8acc4c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java @@ -23,9 +23,9 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import javax.cache.processor.*; @@ -102,7 +102,6 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage imp /** Key bytes. */ @GridToStringInclude @GridDirectCollection(byte[].class) - @GridDirectVersion(1) private List nearKeyBytes; /** Values to update. */ @@ -113,11 +112,9 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage imp /** Value bytes. */ @GridToStringInclude @GridDirectCollection(GridCacheValueBytes.class) - @GridDirectVersion(1) private List nearValBytes; /** Force transform backups flag. */ - @GridDirectVersion(2) private boolean forceTransformBackups; /** Entry processors. */ @@ -126,7 +123,6 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage imp /** Entry processors bytes. */ @GridDirectCollection(byte[].class) - @GridDirectVersion(2) private List entryProcessorsBytes; /** Near entry processors. */ @@ -135,7 +131,6 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage imp /** Near entry processors bytes. */ @GridDirectCollection(byte[].class) - @GridDirectVersion(2) private List nearEntryProcessorsBytes; /** Optional arguments for entry processor. */ @@ -146,11 +141,9 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage imp private byte[][] invokeArgsBytes; /** Subject ID. */ - @GridDirectVersion(3) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(4) private int taskNameHash; /** @@ -689,7 +682,7 @@ public long nearExpireTime(int idx) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtAtomicUpdateRequest _clone = new GridDhtAtomicUpdateRequest(); clone0(_clone); @@ -698,24 +691,24 @@ public long nearExpireTime(int idx) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtAtomicUpdateRequest _clone = (GridDhtAtomicUpdateRequest)_msg; _clone.nodeId = nodeId; - _clone.futVer = futVer; - _clone.writeVer = writeVer; + _clone.futVer = futVer != null ? (GridCacheVersion)futVer.clone() : null; + _clone.writeVer = writeVer != null ? (GridCacheVersion)writeVer.clone() : null; _clone.topVer = topVer; _clone.keys = keys; _clone.keyBytes = keyBytes; _clone.vals = vals; _clone.valBytes = valBytes; _clone.drVers = drVers; - _clone.ttls = ttls; - _clone.drExpireTimes = drExpireTimes; - _clone.nearTtls = nearTtls; - _clone.nearExpireTimes = nearExpireTimes; + _clone.ttls = ttls != null ? (GridLongList)ttls.clone() : null; + _clone.drExpireTimes = drExpireTimes != null ? (GridLongList)drExpireTimes.clone() : null; + _clone.nearTtls = nearTtls != null ? (GridLongList)nearTtls.clone() : null; + _clone.nearExpireTimes = nearExpireTimes != null ? (GridLongList)nearExpireTimes.clone() : null; _clone.syncMode = syncMode; _clone.nearKeys = nearKeys; _clone.nearKeyBytes = nearKeyBytes; @@ -735,306 +728,138 @@ public long nearExpireTime(int idx) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putLongList(drExpireTimes)) + if (!writer.writeMessage("drExpireTimes", drExpireTimes)) return false; - commState.idx++; + state++; case 4: - if (drVers != null) { - if (commState.it == null) { - if (!commState.putInt(drVers.size())) - return false; - - commState.it = drVers.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("drVers", drVers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 5: - if (!commState.putCacheVersion(futVer)) + if (!writer.writeCollection("entryProcessorsBytes", entryProcessorsBytes, byte[].class)) return false; - commState.idx++; + state++; case 6: - if (invokeArgsBytes != null) { - if (commState.it == null) { - if (!commState.putInt(invokeArgsBytes.length)) - return false; - - commState.it = arrayIterator(invokeArgsBytes); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeBoolean("forceTransformBackups", forceTransformBackups)) + return false; - commState.idx++; + state++; case 7: - if (keyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(keyBytes.size())) - return false; - - commState.it = keyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMessage("futVer", futVer)) + return false; - commState.idx++; + state++; case 8: - if (!commState.putLongList(nearExpireTimes)) + if (!writer.writeObjectArray("invokeArgsBytes", invokeArgsBytes, byte[].class)) return false; - commState.idx++; + state++; case 9: - if (!commState.putLongList(nearTtls)) + if (!writer.writeCollection("keyBytes", keyBytes, byte[].class)) return false; - commState.idx++; + state++; case 10: - if (!commState.putUuid(nodeId)) + if (!writer.writeCollection("nearEntryProcessorsBytes", nearEntryProcessorsBytes, byte[].class)) return false; - commState.idx++; + state++; case 11: - if (!commState.putEnum(syncMode)) + if (!writer.writeMessage("nearExpireTimes", nearExpireTimes)) return false; - commState.idx++; + state++; case 12: - if (!commState.putLong(topVer)) + if (!writer.writeCollection("nearKeyBytes", nearKeyBytes, byte[].class)) return false; - commState.idx++; + state++; case 13: - if (!commState.putLongList(ttls)) + if (!writer.writeMessage("nearTtls", nearTtls)) return false; - commState.idx++; + state++; case 14: - if (valBytes != null) { - if (commState.it == null) { - if (!commState.putInt(valBytes.size())) - return false; - - commState.it = valBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putValueBytes((GridCacheValueBytes)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearValBytes", nearValBytes, GridCacheValueBytes.class)) + return false; - commState.idx++; + state++; case 15: - if (!commState.putCacheVersion(writeVer)) + if (!writer.writeUuid("nodeId", nodeId)) return false; - commState.idx++; + state++; case 16: - if (nearKeyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearKeyBytes.size())) - return false; - - commState.it = nearKeyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeUuid("subjId", subjId)) + return false; - commState.idx++; + state++; case 17: - if (nearValBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearValBytes.size())) - return false; - - commState.it = nearValBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putValueBytes((GridCacheValueBytes)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeEnum("syncMode", syncMode)) + return false; - commState.idx++; + state++; case 18: - if (entryProcessorsBytes != null) { - if (commState.it == null) { - if (!commState.putInt(entryProcessorsBytes.size())) - return false; - - commState.it = entryProcessorsBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeInt("taskNameHash", taskNameHash)) + return false; - commState.idx++; + state++; case 19: - if (!commState.putBoolean(forceTransformBackups)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; case 20: - if (nearEntryProcessorsBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearEntryProcessorsBytes.size())) - return false; - - commState.it = nearEntryProcessorsBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMessage("ttls", ttls)) + return false; - commState.idx++; + state++; case 21: - if (!commState.putUuid(subjId)) + if (!writer.writeCollection("valBytes", valBytes, GridCacheValueBytes.class)) return false; - commState.idx++; + state++; case 22: - if (!commState.putInt(taskNameHash)) + if (!writer.writeMessage("writeVer", writeVer)) return false; - commState.idx++; + state++; } @@ -1044,357 +869,171 @@ public long nearExpireTime(int idx) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - GridLongList drExpireTimes0 = commState.getLongList(); + drExpireTimes = reader.readMessage("drExpireTimes"); - if (drExpireTimes0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - drExpireTimes = drExpireTimes0; - - commState.idx++; + state++; case 4: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (drVers == null) - drVers = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - drVers.add((GridCacheVersion)_val); + drVers = reader.readCollection("drVers", GridCacheVersion.class); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - GridCacheVersion futVer0 = commState.getCacheVersion(); + entryProcessorsBytes = reader.readCollection("entryProcessorsBytes", byte[].class); - if (futVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - futVer = futVer0; - - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (invokeArgsBytes == null) - invokeArgsBytes = new byte[commState.readSize][]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + forceTransformBackups = reader.readBoolean("forceTransformBackups"); - invokeArgsBytes[i] = (byte[])_val; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (keyBytes == null) - keyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - keyBytes.add((byte[])_val); + futVer = reader.readMessage("futVer"); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 8: - GridLongList nearExpireTimes0 = commState.getLongList(); + invokeArgsBytes = reader.readObjectArray("invokeArgsBytes", byte[].class); - if (nearExpireTimes0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - nearExpireTimes = nearExpireTimes0; - - commState.idx++; + state++; case 9: - GridLongList nearTtls0 = commState.getLongList(); + keyBytes = reader.readCollection("keyBytes", byte[].class); - if (nearTtls0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - nearTtls = nearTtls0; - - commState.idx++; + state++; case 10: - UUID nodeId0 = commState.getUuid(); + nearEntryProcessorsBytes = reader.readCollection("nearEntryProcessorsBytes", byte[].class); - if (nodeId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - nodeId = nodeId0; - - commState.idx++; + state++; case 11: - if (buf.remaining() < 1) - return false; - - byte syncMode0 = commState.getByte(); + nearExpireTimes = reader.readMessage("nearExpireTimes"); - syncMode = CacheWriteSynchronizationMode.fromOrdinal(syncMode0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 12: - if (buf.remaining() < 8) - return false; + nearKeyBytes = reader.readCollection("nearKeyBytes", byte[].class); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 13: - GridLongList ttls0 = commState.getLongList(); + nearTtls = reader.readMessage("nearTtls"); - if (ttls0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - ttls = ttls0; - - commState.idx++; + state++; case 14: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (valBytes == null) - valBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheValueBytes _val = commState.getValueBytes(); - - if (_val == VAL_BYTES_NOT_READ) - return false; + nearValBytes = reader.readCollection("nearValBytes", GridCacheValueBytes.class); - valBytes.add((GridCacheValueBytes)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 15: - GridCacheVersion writeVer0 = commState.getCacheVersion(); + nodeId = reader.readUuid("nodeId"); - if (writeVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - writeVer = writeVer0; - - commState.idx++; + state++; case 16: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearKeyBytes == null) - nearKeyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + subjId = reader.readUuid("subjId"); - if (_val == BYTE_ARR_NOT_READ) - return false; - - nearKeyBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 17: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearValBytes == null) - nearValBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheValueBytes _val = commState.getValueBytes(); - - if (_val == VAL_BYTES_NOT_READ) - return false; + syncMode = reader.readEnum("syncMode", CacheWriteSynchronizationMode.class); - nearValBytes.add((GridCacheValueBytes)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 18: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (entryProcessorsBytes == null) - entryProcessorsBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + taskNameHash = reader.readInt("taskNameHash"); - entryProcessorsBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 19: - if (buf.remaining() < 1) - return false; + topVer = reader.readLong("topVer"); - forceTransformBackups = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 20: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearEntryProcessorsBytes == null) - nearEntryProcessorsBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + ttls = reader.readMessage("ttls"); - if (_val == BYTE_ARR_NOT_READ) - return false; - - nearEntryProcessorsBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 21: - UUID subjId0 = commState.getUuid(); + valBytes = reader.readCollection("valBytes", GridCacheValueBytes.class); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 22: - if (buf.remaining() < 4) - return false; + writeVer = reader.readMessage("writeVer"); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -1403,7 +1042,7 @@ public long nearExpireTime(int idx) { /** {@inheritDoc} */ @Override public byte directType() { - return 37; + return 38; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java index d4e328dcb54a9..94be1c364b42b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java @@ -21,9 +21,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -65,7 +65,6 @@ public class GridDhtAtomicUpdateResponse extends GridCacheMessage im /** Evicted reader key bytes. */ @GridDirectCollection(byte[].class) - @GridDirectVersion(1) private Collection nearEvictedBytes; /** @@ -180,7 +179,7 @@ public void addNearEvicted(K key, @Nullable byte[] bytes) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtAtomicUpdateResponse _clone = new GridDhtAtomicUpdateResponse(); clone0(_clone); @@ -189,12 +188,12 @@ public void addNearEvicted(K key, @Nullable byte[] bytes) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtAtomicUpdateResponse _clone = (GridDhtAtomicUpdateResponse)_msg; - _clone.futVer = futVer; + _clone.futVer = futVer != null ? (GridCacheVersion)futVer.clone() : null; _clone.failedKeys = failedKeys; _clone.failedKeysBytes = failedKeysBytes; _clone.err = err; @@ -206,63 +205,42 @@ public void addNearEvicted(K key, @Nullable byte[] bytes) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(failedKeysBytes)) + if (!writer.writeByteArray("failedKeysBytes", failedKeysBytes)) return false; - commState.idx++; + state++; case 5: - if (!commState.putCacheVersion(futVer)) + if (!writer.writeMessage("futVer", futVer)) return false; - commState.idx++; + state++; case 6: - if (nearEvictedBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearEvictedBytes.size())) - return false; - - commState.it = nearEvictedBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearEvictedBytes", nearEvictedBytes, byte[].class)) + return false; - commState.idx++; + state++; } @@ -272,70 +250,43 @@ public void addNearEvicted(K key, @Nullable byte[] bytes) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 4: - byte[] failedKeysBytes0 = commState.getByteArray(); + failedKeysBytes = reader.readByteArray("failedKeysBytes"); - if (failedKeysBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - failedKeysBytes = failedKeysBytes0; - - commState.idx++; + state++; case 5: - GridCacheVersion futVer0 = commState.getCacheVersion(); + futVer = reader.readMessage("futVer"); - if (futVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - futVer = futVer0; - - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearEvictedBytes == null) - nearEvictedBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + nearEvictedBytes = reader.readCollection("nearEvictedBytes", byte[].class); - if (_val == BYTE_ARR_NOT_READ) - return false; - - nearEvictedBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -344,7 +295,7 @@ public void addNearEvicted(K key, @Nullable byte[] bytes) { /** {@inheritDoc} */ @Override public byte directType() { - return 38; + return 39; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java index eb12e63c43614..ed5b3b3c0b095 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java @@ -24,10 +24,10 @@ import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import javax.cache.*; @@ -126,15 +126,12 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage im private boolean hasPrimary; /** Force transform backups flag. */ - @GridDirectVersion(2) private boolean forceTransformBackups; /** Subject ID. */ - @GridDirectVersion(3) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(4) private int taskNameHash; /** @@ -547,7 +544,7 @@ public void forceTransformBackups(boolean forceTransformBackups) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearAtomicUpdateRequest _clone = new GridNearAtomicUpdateRequest(); clone0(_clone); @@ -556,15 +553,15 @@ public void forceTransformBackups(boolean forceTransformBackups) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearAtomicUpdateRequest _clone = (GridNearAtomicUpdateRequest)_msg; _clone.nodeId = nodeId; - _clone.futVer = futVer; + _clone.futVer = futVer != null ? (GridCacheVersion)futVer.clone() : null; _clone.fastMap = fastMap; - _clone.updateVer = updateVer; + _clone.updateVer = updateVer != null ? (GridCacheVersion)updateVer.clone() : null; _clone.topVer = topVer; _clone.syncMode = syncMode; _clone.op = op; @@ -575,8 +572,8 @@ public void forceTransformBackups(boolean forceTransformBackups) { _clone.invokeArgs = invokeArgs; _clone.invokeArgsBytes = invokeArgsBytes; _clone.drVers = drVers; - _clone.drTtls = drTtls; - _clone.drExpireTimes = drExpireTimes; + _clone.drTtls = drTtls != null ? (GridLongList)drTtls.clone() : null; + _clone.drExpireTimes = drExpireTimes != null ? (GridLongList)drExpireTimes.clone() : null; _clone.retval = retval; _clone.expiryPlc = expiryPlc; _clone.expiryPlcBytes = expiryPlcBytes; @@ -591,237 +588,132 @@ public void forceTransformBackups(boolean forceTransformBackups) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putLongList(drExpireTimes)) + if (!writer.writeMessage("drExpireTimes", drExpireTimes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putLongList(drTtls)) + if (!writer.writeMessage("drTtls", drTtls)) return false; - commState.idx++; + state++; case 5: - if (drVers != null) { - if (commState.it == null) { - if (!commState.putInt(drVers.size())) - return false; - - commState.it = drVers.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("drVers", drVers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 6: - if (!commState.putByteArray(expiryPlcBytes)) + if (!writer.writeByteArray("expiryPlcBytes", expiryPlcBytes)) return false; - commState.idx++; + state++; case 7: - if (!commState.putBoolean(fastMap)) + if (!writer.writeBoolean("fastMap", fastMap)) return false; - commState.idx++; + state++; case 8: - if (filterBytes != null) { - if (commState.it == null) { - if (!commState.putInt(filterBytes.length)) - return false; - - commState.it = arrayIterator(filterBytes); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeObjectArray("filterBytes", filterBytes, byte[].class)) + return false; - commState.idx++; + state++; case 9: - if (!commState.putCacheVersion(futVer)) + if (!writer.writeBoolean("forceTransformBackups", forceTransformBackups)) return false; - commState.idx++; + state++; case 10: - if (!commState.putBoolean(hasPrimary)) + if (!writer.writeMessage("futVer", futVer)) return false; - commState.idx++; + state++; case 11: - if (invokeArgsBytes != null) { - if (commState.it == null) { - if (!commState.putInt(invokeArgsBytes.length)) - return false; - - commState.it = arrayIterator(invokeArgsBytes); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeBoolean("hasPrimary", hasPrimary)) + return false; - commState.idx++; + state++; case 12: - if (keyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(keyBytes.size())) - return false; - - commState.it = keyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeObjectArray("invokeArgsBytes", invokeArgsBytes, byte[].class)) + return false; - commState.idx++; + state++; case 13: - if (!commState.putEnum(op)) + if (!writer.writeCollection("keyBytes", keyBytes, byte[].class)) return false; - commState.idx++; + state++; case 14: - if (!commState.putBoolean(retval)) + if (!writer.writeEnum("op", op)) return false; - commState.idx++; + state++; case 15: - if (!commState.putEnum(syncMode)) + if (!writer.writeBoolean("retval", retval)) return false; - commState.idx++; + state++; case 16: - if (!commState.putLong(topVer)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 17: - if (!commState.putCacheVersion(updateVer)) + if (!writer.writeEnum("syncMode", syncMode)) return false; - commState.idx++; + state++; case 18: - if (valBytes != null) { - if (commState.it == null) { - if (!commState.putInt(valBytes.size())) - return false; - - commState.it = valBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putValueBytes((GridCacheValueBytes)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeInt("taskNameHash", taskNameHash)) + return false; - commState.idx++; + state++; case 19: - if (!commState.putBoolean(forceTransformBackups)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; case 20: - if (!commState.putUuid(subjId)) + if (!writer.writeMessage("updateVer", updateVer)) return false; - commState.idx++; + state++; case 21: - if (!commState.putInt(taskNameHash)) + if (!writer.writeCollection("valBytes", valBytes, GridCacheValueBytes.class)) return false; - commState.idx++; + state++; } @@ -831,284 +723,163 @@ public void forceTransformBackups(boolean forceTransformBackups) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - GridLongList drExpireTimes0 = commState.getLongList(); + drExpireTimes = reader.readMessage("drExpireTimes"); - if (drExpireTimes0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - drExpireTimes = drExpireTimes0; - - commState.idx++; + state++; case 4: - GridLongList drTtls0 = commState.getLongList(); + drTtls = reader.readMessage("drTtls"); - if (drTtls0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - drTtls = drTtls0; - - commState.idx++; + state++; case 5: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (drVers == null) - drVers = new ArrayList<>(commState.readSize); + drVers = reader.readCollection("drVers", GridCacheVersion.class); - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - drVers.add((GridCacheVersion)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 6: - byte[] expiryPlcBytes0 = commState.getByteArray(); + expiryPlcBytes = reader.readByteArray("expiryPlcBytes"); - if (expiryPlcBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - expiryPlcBytes = expiryPlcBytes0; - - commState.idx++; + state++; case 7: - if (buf.remaining() < 1) - return false; + fastMap = reader.readBoolean("fastMap"); - fastMap = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 8: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (filterBytes == null) - filterBytes = new byte[commState.readSize][]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + filterBytes = reader.readObjectArray("filterBytes", byte[].class); - if (_val == BYTE_ARR_NOT_READ) - return false; - - filterBytes[i] = (byte[])_val; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 9: - GridCacheVersion futVer0 = commState.getCacheVersion(); + forceTransformBackups = reader.readBoolean("forceTransformBackups"); - if (futVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - futVer = futVer0; - - commState.idx++; + state++; case 10: - if (buf.remaining() < 1) - return false; + futVer = reader.readMessage("futVer"); - hasPrimary = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 11: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (invokeArgsBytes == null) - invokeArgsBytes = new byte[commState.readSize][]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + hasPrimary = reader.readBoolean("hasPrimary"); - invokeArgsBytes[i] = (byte[])_val; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 12: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (keyBytes == null) - keyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + invokeArgsBytes = reader.readObjectArray("invokeArgsBytes", byte[].class); - if (_val == BYTE_ARR_NOT_READ) - return false; - - keyBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 13: - if (buf.remaining() < 1) - return false; + keyBytes = reader.readCollection("keyBytes", byte[].class); - byte op0 = commState.getByte(); - - op = GridCacheOperation.fromOrdinal(op0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 14: - if (buf.remaining() < 1) - return false; + op = reader.readEnum("op", GridCacheOperation.class); - retval = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 15: - if (buf.remaining() < 1) - return false; - - byte syncMode0 = commState.getByte(); + retval = reader.readBoolean("retval"); - syncMode = CacheWriteSynchronizationMode.fromOrdinal(syncMode0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 16: - if (buf.remaining() < 8) - return false; + subjId = reader.readUuid("subjId"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 17: - GridCacheVersion updateVer0 = commState.getCacheVersion(); + syncMode = reader.readEnum("syncMode", CacheWriteSynchronizationMode.class); - if (updateVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - updateVer = updateVer0; - - commState.idx++; + state++; case 18: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + taskNameHash = reader.readInt("taskNameHash"); - if (commState.readSize >= 0) { - if (valBytes == null) - valBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheValueBytes _val = commState.getValueBytes(); - - if (_val == VAL_BYTES_NOT_READ) - return false; - - valBytes.add((GridCacheValueBytes)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 19: - if (buf.remaining() < 1) - return false; + topVer = reader.readLong("topVer"); - forceTransformBackups = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 20: - UUID subjId0 = commState.getUuid(); + updateVer = reader.readMessage("updateVer"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 21: - if (buf.remaining() < 4) - return false; + valBytes = reader.readCollection("valBytes", GridCacheValueBytes.class); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -1117,7 +888,7 @@ public void forceTransformBackups(boolean forceTransformBackups) { /** {@inheritDoc} */ @Override public byte directType() { - return 39; + return 40; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java index e88de2efe7409..05b74635bdc37 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java @@ -22,9 +22,9 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -81,12 +81,10 @@ public class GridNearAtomicUpdateResponse extends GridCacheMessage i /** Indexes of keys for which values were generated on primary node (used if originating node has near cache). */ @GridDirectCollection(int.class) - @GridDirectVersion(1) private List nearValsIdxs; /** Indexes of keys for which update was skipped (used if originating node has near cache). */ @GridDirectCollection(int.class) - @GridDirectVersion(1) private List nearSkipIdxs; /** Values generated on primary node which should be put to originating node's near cache. */ @@ -97,11 +95,9 @@ public class GridNearAtomicUpdateResponse extends GridCacheMessage i /** Serialized values generated on primary node which should be put to originating node's near cache. */ @GridToStringInclude @GridDirectCollection(GridCacheValueBytes.class) - @GridDirectVersion(1) private List nearValBytes; /** Version generated on primary node to be used for originating node's near cache update. */ - @GridDirectVersion(1) private GridCacheVersion nearVer; /** Near TTLs. */ @@ -423,7 +419,7 @@ public synchronized void addFailedKeys(Collection keys, Throwable e) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearAtomicUpdateResponse _clone = new GridNearAtomicUpdateResponse(); clone0(_clone); @@ -432,13 +428,13 @@ public synchronized void addFailedKeys(Collection keys, Throwable e) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearAtomicUpdateResponse _clone = (GridNearAtomicUpdateResponse)_msg; _clone.nodeId = nodeId; - _clone.futVer = futVer; + _clone.futVer = futVer != null ? (GridCacheVersion)futVer.clone() : null; _clone.err = err; _clone.errBytes = errBytes; _clone.retVal = retVal; @@ -451,155 +447,93 @@ public synchronized void addFailedKeys(Collection keys, Throwable e) { _clone.nearSkipIdxs = nearSkipIdxs; _clone.nearVals = nearVals; _clone.nearValBytes = nearValBytes; - _clone.nearVer = nearVer; - _clone.nearTtls = nearTtls; - _clone.nearExpireTimes = nearExpireTimes; + _clone.nearVer = nearVer != null ? (GridCacheVersion)nearVer.clone() : null; + _clone.nearTtls = nearTtls != null ? (GridLongList)nearTtls.clone() : null; + _clone.nearExpireTimes = nearExpireTimes != null ? (GridLongList)nearExpireTimes.clone() : null; } /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(failedKeysBytes)) + if (!writer.writeByteArray("failedKeysBytes", failedKeysBytes)) return false; - commState.idx++; + state++; case 5: - if (!commState.putCacheVersion(futVer)) + if (!writer.writeMessage("futVer", futVer)) return false; - commState.idx++; + state++; case 6: - if (!commState.putByteArray(remapKeysBytes)) + if (!writer.writeMessage("nearExpireTimes", nearExpireTimes)) return false; - commState.idx++; + state++; case 7: - if (!commState.putByteArray(retValBytes)) + if (!writer.writeCollection("nearSkipIdxs", nearSkipIdxs, int.class)) return false; - commState.idx++; + state++; case 8: - if (nearSkipIdxs != null) { - if (commState.it == null) { - if (!commState.putInt(nearSkipIdxs.size())) - return false; - - commState.it = nearSkipIdxs.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMessage("nearTtls", nearTtls)) + return false; - commState.idx++; + state++; case 9: - if (nearValBytes != null) { - if (commState.it == null) { - if (!commState.putInt(nearValBytes.size())) - return false; - - commState.it = nearValBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putValueBytes((GridCacheValueBytes)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearValBytes", nearValBytes, GridCacheValueBytes.class)) + return false; - commState.idx++; + state++; case 10: - if (nearValsIdxs != null) { - if (commState.it == null) { - if (!commState.putInt(nearValsIdxs.size())) - return false; - - commState.it = nearValsIdxs.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("nearValsIdxs", nearValsIdxs, int.class)) + return false; - commState.idx++; + state++; case 11: - if (!commState.putCacheVersion(nearVer)) + if (!writer.writeMessage("nearVer", nearVer)) return false; - commState.idx++; + state++; case 12: - if (!commState.putLongList(nearExpireTimes)) + if (!writer.writeByteArray("remapKeysBytes", remapKeysBytes)) return false; - commState.idx++; + state++; case 13: - if (!commState.putLongList(nearTtls)) + if (!writer.writeByteArray("retValBytes", retValBytes)) return false; - commState.idx++; + state++; + } return true; @@ -608,178 +542,99 @@ public synchronized void addFailedKeys(Collection keys, Throwable e) { /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 4: - byte[] failedKeysBytes0 = commState.getByteArray(); + failedKeysBytes = reader.readByteArray("failedKeysBytes"); - if (failedKeysBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - failedKeysBytes = failedKeysBytes0; - - commState.idx++; + state++; case 5: - GridCacheVersion futVer0 = commState.getCacheVersion(); + futVer = reader.readMessage("futVer"); - if (futVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - futVer = futVer0; - - commState.idx++; + state++; case 6: - byte[] remapKeysBytes0 = commState.getByteArray(); + nearExpireTimes = reader.readMessage("nearExpireTimes"); - if (remapKeysBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - remapKeysBytes = remapKeysBytes0; - - commState.idx++; + state++; case 7: - byte[] retValBytes0 = commState.getByteArray(); + nearSkipIdxs = reader.readCollection("nearSkipIdxs", int.class); - if (retValBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - retValBytes = retValBytes0; - - commState.idx++; + state++; case 8: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; + nearTtls = reader.readMessage("nearTtls"); - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearSkipIdxs == null) - nearSkipIdxs = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; - - int _val = commState.getInt(); - - nearSkipIdxs.add((Integer)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 9: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearValBytes == null) - nearValBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheValueBytes _val = commState.getValueBytes(); - - if (_val == VAL_BYTES_NOT_READ) - return false; - - nearValBytes.add((GridCacheValueBytes)_val); + nearValBytes = reader.readCollection("nearValBytes", GridCacheValueBytes.class); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 10: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (nearValsIdxs == null) - nearValsIdxs = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; - - int _val = commState.getInt(); + nearValsIdxs = reader.readCollection("nearValsIdxs", int.class); - nearValsIdxs.add((Integer)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 11: - GridCacheVersion nearVer0 = commState.getCacheVersion(); + nearVer = reader.readMessage("nearVer"); - if (nearVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - nearVer = nearVer0; - - commState.idx++; + state++; case 12: - GridLongList nearExpireTimes0 = commState.getLongList(); + remapKeysBytes = reader.readByteArray("remapKeysBytes"); - if (nearExpireTimes0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - nearExpireTimes = nearExpireTimes0; - - commState.idx++; + state++; case 13: - GridLongList nearTtls0 = commState.getLongList(); + retValBytes = reader.readByteArray("retValBytes"); - if (nearTtls0 == LONG_LIST_NOT_READ) + if (!reader.isLastRead()) return false; - nearTtls = nearTtls0; - - commState.idx++; + state++; } @@ -788,7 +643,7 @@ public synchronized void addFailedKeys(Collection keys, Throwable e) { /** {@inheritDoc} */ @Override public byte directType() { - return 40; + return 41; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java index 9300bf4e7239f..60c4a9a2a8622 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java @@ -20,11 +20,11 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -163,7 +163,7 @@ private int keyCount() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtForceKeysRequest _clone = new GridDhtForceKeysRequest(); clone0(_clone); @@ -172,7 +172,7 @@ private int keyCount() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtForceKeysRequest _clone = (GridDhtForceKeysRequest)_msg; @@ -187,63 +187,42 @@ private int keyCount() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 4: - if (keyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(keyBytes.size())) - return false; - - commState.it = keyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("keyBytes", keyBytes, byte[].class)) + return false; - commState.idx++; + state++; case 5: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 6: - if (!commState.putLong(topVer)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; } @@ -253,68 +232,43 @@ private int keyCount() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 4: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (keyBytes == null) - keyBytes = new ArrayList<>(commState.readSize); + keyBytes = reader.readCollection("keyBytes", byte[].class); - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - keyBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 6: - if (buf.remaining() < 8) - return false; + topVer = reader.readLong("topVer"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -323,7 +277,7 @@ private int keyCount() { /** {@inheritDoc} */ @Override public byte directType() { - return 41; + return 42; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java index 9b22946a6200a..ff8cdca66ba00 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java @@ -20,10 +20,10 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -166,7 +166,7 @@ public void addInfo(GridCacheEntryInfo info) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtForceKeysResponse _clone = new GridDhtForceKeysResponse(); clone0(_clone); @@ -175,7 +175,7 @@ public void addInfo(GridCacheEntryInfo info) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtForceKeysResponse _clone = (GridDhtForceKeysResponse)_msg; @@ -191,63 +191,42 @@ public void addInfo(GridCacheEntryInfo info) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(infosBytes)) + if (!writer.writeByteArray("infosBytes", infosBytes)) return false; - commState.idx++; + state++; case 5: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 6: - if (missedKeyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(missedKeyBytes.size())) - return false; - - commState.it = missedKeyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("missedKeyBytes", missedKeyBytes, byte[].class)) + return false; - commState.idx++; + state++; } @@ -257,70 +236,43 @@ public void addInfo(GridCacheEntryInfo info) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 4: - byte[] infosBytes0 = commState.getByteArray(); + infosBytes = reader.readByteArray("infosBytes"); - if (infosBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - infosBytes = infosBytes0; - - commState.idx++; + state++; case 5: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (missedKeyBytes == null) - missedKeyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + missedKeyBytes = reader.readCollection("missedKeyBytes", byte[].class); - if (_val == BYTE_ARR_NOT_READ) - return false; - - missedKeyBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -329,7 +281,7 @@ public void addInfo(GridCacheEntryInfo info) { /** {@inheritDoc} */ @Override public byte directType() { - return 42; + return 43; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java index 29568c9b62e59..29760f67e95a4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java @@ -20,9 +20,9 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -41,7 +41,7 @@ public class GridDhtPartitionDemandMessage extends GridCacheMessage /** Partition. */ @GridToStringInclude @GridDirectCollection(int.class) - private Set parts; + private Collection parts; /** Topic. */ @GridDirectTransient @@ -112,7 +112,7 @@ void addPartition(int p) { /** * @return Partition. */ - Set partitions() { + Collection partitions() { return parts; } @@ -191,7 +191,7 @@ void workerId(int workerId) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtPartitionDemandMessage _clone = new GridDhtPartitionDemandMessage(); clone0(_clone); @@ -200,7 +200,7 @@ void workerId(int workerId) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtPartitionDemandMessage _clone = (GridDhtPartitionDemandMessage)_msg; @@ -217,75 +217,54 @@ void workerId(int workerId) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (parts != null) { - if (commState.it == null) { - if (!commState.putInt(parts.size())) - return false; - - commState.it = parts.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("parts", parts, int.class)) + return false; - commState.idx++; + state++; case 4: - if (!commState.putLong(timeout)) + if (!writer.writeLong("timeout", timeout)) return false; - commState.idx++; + state++; case 5: - if (!commState.putLong(topVer)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; case 6: - if (!commState.putByteArray(topicBytes)) + if (!writer.writeByteArray("topicBytes", topicBytes)) return false; - commState.idx++; + state++; case 7: - if (!commState.putLong(updateSeq)) + if (!writer.writeLong("updateSeq", updateSeq)) return false; - commState.idx++; + state++; case 8: - if (!commState.putInt(workerId)) + if (!writer.writeInt("workerId", workerId)) return false; - commState.idx++; + state++; } @@ -295,82 +274,59 @@ void workerId(int workerId) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (parts == null) - parts = new HashSet<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; - - int _val = commState.getInt(); - - parts.add((Integer)_val); + parts = reader.readCollection("parts", int.class); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (buf.remaining() < 8) - return false; + timeout = reader.readLong("timeout"); - timeout = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - if (buf.remaining() < 8) - return false; + topVer = reader.readLong("topVer"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 6: - byte[] topicBytes0 = commState.getByteArray(); + topicBytes = reader.readByteArray("topicBytes"); - if (topicBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - topicBytes = topicBytes0; - - commState.idx++; + state++; case 7: - if (buf.remaining() < 8) - return false; + updateSeq = reader.readLong("updateSeq"); - updateSeq = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 8: - if (buf.remaining() < 4) - return false; + workerId = reader.readInt("workerId"); - workerId = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -379,7 +335,7 @@ void workerId(int workerId) { /** {@inheritDoc} */ @Override public byte directType() { - return 43; + return 44; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java index d64a68612aa10..c46b4c5bde00f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java @@ -19,8 +19,10 @@ import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; +import java.nio.*; import java.util.*; import static org.apache.ignite.events.EventType.*; @@ -28,7 +30,8 @@ /** * Exchange ID. */ -public class GridDhtPartitionExchangeId implements Comparable, Externalizable { +public class GridDhtPartitionExchangeId extends MessageAdapter implements Comparable, + Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -142,6 +145,99 @@ public boolean isLeft() { return evt == id.evt && topVer == id.topVer && nodeId.equals(id.nodeId); } + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf) { + writer.setBuffer(buf); + + if (!typeWritten) { + if (!writer.writeByte(null, directType())) + return false; + + typeWritten = true; + } + + switch (state) { + case 0: + if (!writer.writeInt("evt", evt)) + return false; + + state++; + + case 1: + if (!writer.writeUuid("nodeId", nodeId)) + return false; + + state++; + + case 2: + if (!writer.writeLong("topVer", topVer)) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf) { + reader.setBuffer(buf); + + switch (state) { + case 0: + evt = reader.readInt("evt"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 1: + nodeId = reader.readUuid("nodeId"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 2: + topVer = reader.readLong("topVer"); + + if (!reader.isLastRead()) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public byte directType() { + return 87; + } + + /** {@inheritDoc} */ + @SuppressWarnings("CloneDoesntCallSuperClone") + @Override public MessageAdapter clone() { + GridDhtPartitionExchangeId _clone = new GridDhtPartitionExchangeId(); + + clone0(_clone); + + return _clone; + } + + /** {@inheritDoc} */ + @Override protected void clone0(MessageAdapter _msg) { + GridDhtPartitionExchangeId _clone = (GridDhtPartitionExchangeId)_msg; + + _clone.nodeId = nodeId; + _clone.evt = evt; + _clone.topVer = topVer; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtPartitionExchangeId.class, this, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java index b1c6f45b626a6..ee1a930ea84f2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java @@ -20,9 +20,9 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -46,12 +46,12 @@ public class GridDhtPartitionSupplyMessage extends GridCacheMessage /** Partitions that have been fully sent. */ @GridDirectCollection(int.class) - private Set last; + private Collection last; /** Partitions which were not found. */ @GridToStringInclude @GridDirectCollection(int.class) - private Set missed; + private Collection missed; /** Entries. */ @GridDirectTransient @@ -130,7 +130,7 @@ boolean ack() { /** * @return Flag to indicate last message for partition. */ - Set last() { + Collection last() { return last == null ? Collections.emptySet() : last; } @@ -166,7 +166,7 @@ void missed(int p) { /** * @return Missed partitions. */ - Set missed() { + Collection missed() { return missed == null ? Collections.emptySet() : missed; } @@ -274,7 +274,7 @@ public int size() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtPartitionSupplyMessage _clone = new GridDhtPartitionSupplyMessage(); clone0(_clone); @@ -283,7 +283,7 @@ public int size() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtPartitionSupplyMessage _clone = (GridDhtPartitionSupplyMessage)_msg; @@ -302,96 +302,54 @@ public int size() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putBoolean(ack)) + if (!writer.writeBoolean("ack", ack)) return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(infoBytes)) + if (!writer.writeByteArray("infoBytes", infoBytes)) return false; - commState.idx++; + state++; case 5: - if (last != null) { - if (commState.it == null) { - if (!commState.putInt(last.size())) - return false; - - commState.it = last.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("last", last, int.class)) + return false; - commState.idx++; + state++; case 6: - if (missed != null) { - if (commState.it == null) { - if (!commState.putInt(missed.size())) - return false; - - commState.it = missed.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("missed", missed, int.class)) + return false; - commState.idx++; + state++; case 7: - if (!commState.putLong(updateSeq)) + if (!writer.writeLong("updateSeq", updateSeq)) return false; - commState.idx++; + state++; case 8: - if (!commState.putInt(workerId)) + if (!writer.writeInt("workerId", workerId)) return false; - commState.idx++; + state++; } @@ -401,103 +359,59 @@ public int size() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (buf.remaining() < 1) - return false; + ack = reader.readBoolean("ack"); - ack = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - byte[] infoBytes0 = commState.getByteArray(); + infoBytes = reader.readByteArray("infoBytes"); - if (infoBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - infoBytes = infoBytes0; - - commState.idx++; + state++; case 5: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (last == null) - last = new HashSet<>(commState.readSize); + last = reader.readCollection("last", int.class); - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; - - int _val = commState.getInt(); - - last.add((Integer)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (missed == null) - missed = new HashSet<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; + missed = reader.readCollection("missed", int.class); - int _val = commState.getInt(); - - missed.add((Integer)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - if (buf.remaining() < 8) - return false; + updateSeq = reader.readLong("updateSeq"); - updateSeq = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 8: - if (buf.remaining() < 4) - return false; + workerId = reader.readInt("workerId"); - workerId = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -506,7 +420,7 @@ public int size() { /** {@inheritDoc} */ @Override public byte directType() { - return 44; + return 45; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsAbstractMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsAbstractMessage.java index 1f55c5971696b..763152a405b92 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsAbstractMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsAbstractMessage.java @@ -19,8 +19,8 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -75,42 +75,42 @@ public GridDhtPartitionExchangeId exchangeId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtPartitionsAbstractMessage _clone = (GridDhtPartitionsAbstractMessage)_msg; - _clone.exchId = exchId; - _clone.lastVer = lastVer; + _clone.exchId = exchId != null ? (GridDhtPartitionExchangeId)exchId.clone() : null; + _clone.lastVer = lastVer != null ? (GridCacheVersion)lastVer.clone() : null; } /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putDhtPartitionExchangeId(exchId)) + if (!writer.writeMessage("exchId", exchId)) return false; - commState.idx++; + state++; case 4: - if (!commState.putCacheVersion(lastVer)) + if (!writer.writeMessage("lastVer", lastVer)) return false; - commState.idx++; + state++; } @@ -120,31 +120,27 @@ public GridDhtPartitionExchangeId exchangeId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - GridDhtPartitionExchangeId exchId0 = commState.getDhtPartitionExchangeId(); + exchId = reader.readMessage("exchId"); - if (exchId0 == DHT_PART_EXCHANGE_ID_NOT_READ) + if (!reader.isLastRead()) return false; - exchId = exchId0; - - commState.idx++; + state++; case 4: - GridCacheVersion lastVer0 = commState.getCacheVersion(); + lastVer = reader.readMessage("lastVer"); - if (lastVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - lastVer = lastVer0; - - commState.idx++; + state++; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java index 3f8cefb652055..d8dd3b1a0b2aa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java @@ -22,9 +22,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -144,7 +144,7 @@ public void affinityAssignment(List> affAssignment) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtPartitionsFullMessage _clone = new GridDhtPartitionsFullMessage(); clone0(_clone); @@ -153,7 +153,7 @@ public void affinityAssignment(List> affAssignment) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtPartitionsFullMessage _clone = (GridDhtPartitionsFullMessage)_msg; @@ -168,36 +168,36 @@ public void affinityAssignment(List> affAssignment) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 5: - if (!commState.putByteArray(affAssignmentBytes)) + if (!writer.writeByteArray("affAssignmentBytes", affAssignmentBytes)) return false; - commState.idx++; + state++; case 6: - if (!commState.putByteArray(partsBytes)) + if (!writer.writeByteArray("partsBytes", partsBytes)) return false; - commState.idx++; + state++; case 7: - if (!commState.putLong(topVer)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; } @@ -207,39 +207,35 @@ public void affinityAssignment(List> affAssignment) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 5: - byte[] affAssignmentBytes0 = commState.getByteArray(); + affAssignmentBytes = reader.readByteArray("affAssignmentBytes"); - if (affAssignmentBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - affAssignmentBytes = affAssignmentBytes0; - - commState.idx++; + state++; case 6: - byte[] partsBytes0 = commState.getByteArray(); + partsBytes = reader.readByteArray("partsBytes"); - if (partsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - partsBytes = partsBytes0; - - commState.idx++; + state++; case 7: - if (buf.remaining() < 8) - return false; + topVer = reader.readLong("topVer"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -248,7 +244,7 @@ public void affinityAssignment(List> affAssignment) { /** {@inheritDoc} */ @Override public byte directType() { - return 45; + return 46; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java index 00fef2b5d5fa7..d9c9e4527a57c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java @@ -21,9 +21,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -96,7 +96,7 @@ public Map partitions() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtPartitionsSingleMessage _clone = new GridDhtPartitionsSingleMessage(); clone0(_clone); @@ -105,7 +105,7 @@ public Map partitions() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridDhtPartitionsSingleMessage _clone = (GridDhtPartitionsSingleMessage)_msg; @@ -117,24 +117,24 @@ public Map partitions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 5: - if (!commState.putByteArray(partsBytes)) + if (!writer.writeByteArray("partsBytes", partsBytes)) return false; - commState.idx++; + state++; } @@ -144,21 +144,19 @@ public Map partitions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 5: - byte[] partsBytes0 = commState.getByteArray(); + partsBytes = reader.readByteArray("partsBytes"); - if (partsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - partsBytes = partsBytes0; - - commState.idx++; + state++; } @@ -167,7 +165,7 @@ public Map partitions() { /** {@inheritDoc} */ @Override public byte directType() { - return 46; + return 47; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleRequest.java index 01aeb46a15c1f..944fcc0ae7f9c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleRequest.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.processors.cache.distributed.dht.preloader; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -46,7 +46,7 @@ public GridDhtPartitionsSingleRequest() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDhtPartitionsSingleRequest _clone = new GridDhtPartitionsSingleRequest(); clone0(_clone); @@ -55,7 +55,7 @@ public GridDhtPartitionsSingleRequest() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); } @@ -63,16 +63,16 @@ public GridDhtPartitionsSingleRequest() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } return true; @@ -81,7 +81,7 @@ public GridDhtPartitionsSingleRequest() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; @@ -91,7 +91,7 @@ public GridDhtPartitionsSingleRequest() { /** {@inheritDoc} */ @Override public byte directType() { - return 47; + return 48; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java index 1f60e3256d815..b1142f0fec29f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java @@ -634,6 +634,11 @@ public void processDhtAtomicUpdateRequest( dht.removeAll(); } + /** {@inheritDoc} */ + @Override public IgniteInternalFuture removeAllAsync() { + return dht.removeAllAsync(); + } + /** {@inheritDoc} */ @Override public IgniteInternalFuture removeAllAsync(IgnitePredicate>[] filter) { return dht.removeAllAsync(keySet(filter)); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java index 134731dacc1a3..f198994bc5dc2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java @@ -784,6 +784,13 @@ private EntryIterator(Iterator> nearIter, Iterator> nearEntriesIterator() { + return iterator(map.entries0().iterator(), !ctx.keepPortable()); + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridNearCacheAdapter.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java index b1f27b5809638..1c18112b6b7a7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java @@ -21,11 +21,11 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import javax.cache.*; import java.io.*; @@ -76,11 +76,9 @@ public class GridNearGetRequest extends GridCacheMessage implements private IgnitePredicate>[] filter; /** Subject ID. */ - @GridDirectVersion(1) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(2) private int taskNameHash; /** TTL for read operation. */ @@ -251,7 +249,7 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearGetRequest _clone = new GridNearGetRequest(); clone0(_clone); @@ -260,14 +258,14 @@ public long accessTtl() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearGetRequest _clone = (GridNearGetRequest)_msg; _clone.futId = futId; _clone.miniId = miniId; - _clone.ver = ver; + _clone.ver = ver != null ? (GridCacheVersion)ver.clone() : null; _clone.keys = keys; _clone.reload = reload; _clone.readThrough = readThrough; @@ -283,137 +281,84 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putLong(accessTtl)) + if (!writer.writeLong("accessTtl", accessTtl)) return false; - commState.idx++; + state++; case 4: - if (filterBytes != null) { - if (commState.it == null) { - if (!commState.putInt(filterBytes.length)) - return false; - - commState.it = arrayIterator(filterBytes); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeObjectArray("filterBytes", filterBytes, byte[].class)) + return false; - commState.idx++; + state++; case 5: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 6: - if (keyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(keyBytes.size())) - return false; - - commState.it = keyBytes.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putByteArray(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putBoolean(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("keyBytes", keyBytes, byte[].class, boolean.class)) + return false; - commState.idx++; + state++; case 7: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 8: - if (!commState.putBoolean(readThrough)) + if (!writer.writeBoolean("readThrough", readThrough)) return false; - commState.idx++; + state++; case 9: - if (!commState.putBoolean(reload)) + if (!writer.writeBoolean("reload", reload)) return false; - commState.idx++; + state++; case 10: - if (!commState.putLong(topVer)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 11: - if (!commState.putCacheVersion(ver)) + if (!writer.writeInt("taskNameHash", taskNameHash)) return false; - commState.idx++; + state++; case 12: - if (!commState.putUuid(subjId)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; case 13: - if (!commState.putInt(taskNameHash)) + if (!writer.writeMessage("ver", ver)) return false; - commState.idx++; + state++; } @@ -423,162 +368,99 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (buf.remaining() < 8) - return false; + accessTtl = reader.readLong("accessTtl"); - accessTtl = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (filterBytes == null) - filterBytes = new byte[commState.readSize][]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - filterBytes[i] = (byte[])_val; - - commState.readItems++; - } - } + filterBytes = reader.readObjectArray("filterBytes", byte[].class); - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (keyBytes == null) - keyBytes = new LinkedHashMap<>(commState.readSize, 1.0f); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } - - if (buf.remaining() < 1) - return false; - - boolean _val = commState.getBoolean(); - - keyBytes.put((byte[])commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } + keyBytes = reader.readMap("keyBytes", byte[].class, boolean.class, true); - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 8: - if (buf.remaining() < 1) - return false; + readThrough = reader.readBoolean("readThrough"); - readThrough = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 9: - if (buf.remaining() < 1) - return false; + reload = reader.readBoolean("reload"); - reload = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 10: - if (buf.remaining() < 8) - return false; + subjId = reader.readUuid("subjId"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 11: - GridCacheVersion ver0 = commState.getCacheVersion(); + taskNameHash = reader.readInt("taskNameHash"); - if (ver0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - ver = ver0; - - commState.idx++; + state++; case 12: - UUID subjId0 = commState.getUuid(); + topVer = reader.readLong("topVer"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 13: - if (buf.remaining() < 4) - return false; + ver = reader.readMessage("ver"); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -587,7 +469,7 @@ public long accessTtl() { /** {@inheritDoc} */ @Override public byte directType() { - return 48; + return 49; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java index 836174f47f128..93d48fbc0bf30 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java @@ -22,10 +22,10 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -201,7 +201,7 @@ public void error(Throwable err) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearGetResponse _clone = new GridNearGetResponse(); clone0(_clone); @@ -210,14 +210,14 @@ public void error(Throwable err) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearGetResponse _clone = (GridNearGetResponse)_msg; _clone.futId = futId; _clone.miniId = miniId; - _clone.ver = ver; + _clone.ver = ver != null ? (GridCacheVersion)ver.clone() : null; _clone.entries = entries; _clone.entriesBytes = entriesBytes; _clone.invalidParts = invalidParts; @@ -229,81 +229,60 @@ public void error(Throwable err) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putByteArray(entriesBytes)) + if (!writer.writeByteArray("entriesBytes", entriesBytes)) return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 5: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 6: - if (invalidParts != null) { - if (commState.it == null) { - if (!commState.putInt(invalidParts.size())) - return false; - - commState.it = invalidParts.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("invalidParts", invalidParts, int.class)) + return false; - commState.idx++; + state++; case 7: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 8: - if (!commState.putLong(topVer)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; case 9: - if (!commState.putCacheVersion(ver)) + if (!writer.writeMessage("ver", ver)) return false; - commState.idx++; + state++; } @@ -313,98 +292,67 @@ public void error(Throwable err) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - byte[] entriesBytes0 = commState.getByteArray(); + entriesBytes = reader.readByteArray("entriesBytes"); - if (entriesBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - entriesBytes = entriesBytes0; - - commState.idx++; + state++; case 4: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 5: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + invalidParts = reader.readCollection("invalidParts", int.class); - if (commState.readSize >= 0) { - if (invalidParts == null) - invalidParts = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; - - int _val = commState.getInt(); - - invalidParts.add((Integer)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 8: - if (buf.remaining() < 8) - return false; + topVer = reader.readLong("topVer"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 9: - GridCacheVersion ver0 = commState.getCacheVersion(); + ver = reader.readMessage("ver"); - if (ver0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - ver = ver0; - - commState.idx++; + state++; } @@ -413,7 +361,7 @@ public void error(Throwable err) { /** {@inheritDoc} */ @Override public byte directType() { - return 49; + return 50; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java index 2e68d916defec..cd02ff6cf22ef 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java @@ -23,10 +23,10 @@ import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; @@ -69,15 +69,12 @@ public class GridNearLockRequest extends GridDistributedLockRequest private GridCacheVersion[] dhtVers; /** Subject ID. */ - @GridDirectVersion(1) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(2) private int taskNameHash; /** Has transforms flag. */ - @GridDirectVersion(3) private boolean hasTransforms; /** Sync commit flag. */ @@ -335,7 +332,7 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearLockRequest _clone = new GridNearLockRequest(); clone0(_clone); @@ -344,7 +341,7 @@ public long accessTtl() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearLockRequest _clone = (GridNearLockRequest)_msg; @@ -367,132 +364,90 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 24: - if (dhtVers != null) { - if (commState.it == null) { - if (!commState.putInt(dhtVers.length)) - return false; - - commState.it = arrayIterator(dhtVers); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeLong("accessTtl", accessTtl)) + return false; - commState.idx++; + state++; case 25: - if (filterBytes != null) { - if (commState.it == null) { - if (!commState.putInt(filterBytes.length)) - return false; - - commState.it = arrayIterator(filterBytes); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeObjectArray("dhtVers", dhtVers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 26: - if (!commState.putBoolean(implicitSingleTx)) + if (!writer.writeObjectArray("filterBytes", filterBytes, byte[].class)) return false; - commState.idx++; + state++; case 27: - if (!commState.putBoolean(implicitTx)) + if (!writer.writeBoolean("hasTransforms", hasTransforms)) return false; - commState.idx++; + state++; case 28: - if (!commState.putGridUuid(miniId)) + if (!writer.writeBoolean("implicitSingleTx", implicitSingleTx)) return false; - commState.idx++; + state++; case 29: - if (!commState.putBoolean(onePhaseCommit)) + if (!writer.writeBoolean("implicitTx", implicitTx)) return false; - commState.idx++; + state++; case 30: - if (!commState.putLong(topVer)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 31: - if (!commState.putUuid(subjId)) + if (!writer.writeBoolean("onePhaseCommit", onePhaseCommit)) return false; - commState.idx++; + state++; case 32: - if (!commState.putInt(taskNameHash)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 33: - if (!commState.putBoolean(hasTransforms)) + if (!writer.writeBoolean("syncCommit", syncCommit)) return false; - commState.idx++; + state++; case 34: - if (!commState.putBoolean(syncCommit)) + if (!writer.writeInt("taskNameHash", taskNameHash)) return false; - commState.idx++; + state++; case 35: - if (!commState.putLong(accessTtl)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; } @@ -502,153 +457,108 @@ public long accessTtl() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 24: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (dhtVers == null) - dhtVers = new GridCacheVersion[commState.readSize]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - dhtVers[i] = (GridCacheVersion)_val; + accessTtl = reader.readLong("accessTtl"); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 25: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (filterBytes == null) - filterBytes = new byte[commState.readSize][]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); + dhtVers = reader.readObjectArray("dhtVers", GridCacheVersion.class); - if (_val == BYTE_ARR_NOT_READ) - return false; - - filterBytes[i] = (byte[])_val; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 26: - if (buf.remaining() < 1) - return false; + filterBytes = reader.readObjectArray("filterBytes", byte[].class); - implicitSingleTx = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 27: - if (buf.remaining() < 1) - return false; + hasTransforms = reader.readBoolean("hasTransforms"); - implicitTx = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 28: - IgniteUuid miniId0 = commState.getGridUuid(); + implicitSingleTx = reader.readBoolean("implicitSingleTx"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 29: - if (buf.remaining() < 1) - return false; + implicitTx = reader.readBoolean("implicitTx"); - onePhaseCommit = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 30: - if (buf.remaining() < 8) - return false; + miniId = reader.readIgniteUuid("miniId"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 31: - UUID subjId0 = commState.getUuid(); + onePhaseCommit = reader.readBoolean("onePhaseCommit"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 32: - if (buf.remaining() < 4) - return false; + subjId = reader.readUuid("subjId"); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 33: - if (buf.remaining() < 1) - return false; + syncCommit = reader.readBoolean("syncCommit"); - hasTransforms = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 34: - if (buf.remaining() < 1) - return false; + taskNameHash = reader.readInt("taskNameHash"); - syncCommit = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 35: - if (buf.remaining() < 8) + topVer = reader.readLong("topVer"); + + if (!reader.isLastRead()) return false; - accessTtl = commState.getLong(); + state++; - commState.idx++; } return true; @@ -656,7 +566,7 @@ public long accessTtl() { /** {@inheritDoc} */ @Override public byte directType() { - return 50; + return 51; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockResponse.java index b2b2dccfe50b4..2769f7abe3fd1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockResponse.java @@ -22,10 +22,10 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -182,7 +182,7 @@ public void addValueBytes( /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearLockResponse _clone = new GridNearLockResponse(); clone0(_clone); @@ -191,7 +191,7 @@ public void addValueBytes( } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearLockResponse _clone = (GridNearLockResponse)_msg; @@ -206,111 +206,48 @@ public void addValueBytes( /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 11: - if (dhtVers != null) { - if (commState.it == null) { - if (!commState.putInt(dhtVers.length)) - return false; - - commState.it = arrayIterator(dhtVers); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeObjectArray("dhtVers", dhtVers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 12: - if (!commState.putBooleanArray(filterRes)) + if (!writer.writeBooleanArray("filterRes", filterRes)) return false; - commState.idx++; + state++; case 13: - if (mappedVers != null) { - if (commState.it == null) { - if (!commState.putInt(mappedVers.length)) - return false; - - commState.it = arrayIterator(mappedVers); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeObjectArray("mappedVers", mappedVers, GridCacheVersion.class)) + return false; - commState.idx++; + state++; case 14: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 15: - if (pending != null) { - if (commState.it == null) { - if (!commState.putInt(pending.size())) - return false; - - commState.it = pending.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("pending", pending, GridCacheVersion.class)) + return false; - commState.idx++; + state++; } @@ -320,118 +257,51 @@ public void addValueBytes( /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 11: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (dhtVers == null) - dhtVers = new GridCacheVersion[commState.readSize]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); + dhtVers = reader.readObjectArray("dhtVers", GridCacheVersion.class); - if (_val == CACHE_VER_NOT_READ) - return false; - - dhtVers[i] = (GridCacheVersion)_val; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 12: - boolean[] filterRes0 = commState.getBooleanArray(); + filterRes = reader.readBooleanArray("filterRes"); - if (filterRes0 == BOOLEAN_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - filterRes = filterRes0; - - commState.idx++; + state++; case 13: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (mappedVers == null) - mappedVers = new GridCacheVersion[commState.readSize]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - mappedVers[i] = (GridCacheVersion)_val; + mappedVers = reader.readObjectArray("mappedVers", GridCacheVersion.class); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 14: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 15: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (pending == null) - pending = new ArrayList<>(commState.readSize); + pending = reader.readCollection("pending", GridCacheVersion.class); - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - pending.add((GridCacheVersion)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -440,7 +310,7 @@ public void addValueBytes( /** {@inheritDoc} */ @Override public byte directType() { - return 51; + return 52; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java index 00164df9ad7da..cfa797a0296c8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java @@ -17,13 +17,12 @@ package org.apache.ignite.internal.processors.cache.distributed.near; -import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.transactions.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -50,11 +49,9 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishReques private long topVer; /** Subject ID. */ - @GridDirectVersion(1) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(2) private int taskNameHash; /** @@ -162,7 +159,7 @@ public int taskNameHash() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearTxFinishRequest _clone = new GridNearTxFinishRequest(); clone0(_clone); @@ -171,7 +168,7 @@ public int taskNameHash() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearTxFinishRequest _clone = (GridNearTxFinishRequest)_msg; @@ -187,54 +184,55 @@ public int taskNameHash() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 21: - if (!commState.putBoolean(explicitLock)) + if (!writer.writeBoolean("explicitLock", explicitLock)) return false; - commState.idx++; + state++; case 22: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 23: - if (!commState.putLong(topVer)) + if (!writer.writeBoolean("storeEnabled", storeEnabled)) return false; - commState.idx++; + state++; case 24: - if (!commState.putUuid(subjId)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 25: - if (!commState.putInt(taskNameHash)) + if (!writer.writeInt("taskNameHash", taskNameHash)) return false; - commState.idx++; + state++; case 26: - if (!commState.putBoolean(storeEnabled)) + if (!writer.writeLong("topVer", topVer)) return false; - commState.idx++; + state++; + } return true; @@ -243,63 +241,60 @@ public int taskNameHash() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 21: - if (buf.remaining() < 1) - return false; + explicitLock = reader.readBoolean("explicitLock"); - explicitLock = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 22: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 23: - if (buf.remaining() < 8) - return false; + storeEnabled = reader.readBoolean("storeEnabled"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 24: - UUID subjId0 = commState.getUuid(); + subjId = reader.readUuid("subjId"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 25: - if (buf.remaining() < 4) - return false; + taskNameHash = reader.readInt("taskNameHash"); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 26: - if (buf.remaining() < 1) + topVer = reader.readLong("topVer"); + + if (!reader.isLastRead()) return false; - storeEnabled = commState.getBoolean(); + state++; - commState.idx++; } return true; @@ -307,7 +302,7 @@ public int taskNameHash() { /** {@inheritDoc} */ @Override public byte directType() { - return 52; + return 53; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishResponse.java index 80eaee07c320a..5e190792163e4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishResponse.java @@ -22,9 +22,9 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -115,7 +115,7 @@ public long threadId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearTxFinishResponse _clone = new GridNearTxFinishResponse(); clone0(_clone); @@ -124,7 +124,7 @@ public long threadId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearTxFinishResponse _clone = (GridNearTxFinishResponse)_msg; @@ -138,36 +138,36 @@ public long threadId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 5: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 6: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 7: - if (!commState.putLong(nearThreadId)) + if (!writer.writeLong("nearThreadId", nearThreadId)) return false; - commState.idx++; + state++; } @@ -177,39 +177,35 @@ public long threadId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 5: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 6: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 7: - if (buf.remaining() < 8) - return false; + nearThreadId = reader.readLong("nearThreadId"); - nearThreadId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -218,7 +214,7 @@ public long threadId() { /** {@inheritDoc} */ @Override public byte directType() { - return 53; + return 54; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java index 089e53cead7a5..9d5f73d89a1c1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java @@ -21,10 +21,10 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.transactions.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -58,11 +58,9 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequ private Collection lastBackups; /** Subject ID. */ - @GridDirectVersion(1) private UUID subjId; /** Task name hash. */ - @GridDirectVersion(2) private int taskNameHash; /** @@ -219,7 +217,7 @@ private Collection> cloneEntries(Collection> cloneEntries(Collection> cloneEntries(Collection> cloneEntries(Collection= 0) { - if (lastBackups == null) - lastBackups = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - UUID _val = commState.getUuid(); + lastBackups = reader.readCollection("lastBackups", UUID.class); - if (_val == UUID_NOT_READ) - return false; - - lastBackups.add((UUID)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 25: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 26: - if (buf.remaining() < 1) - return false; + near = reader.readBoolean("near"); - near = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 27: - if (buf.remaining() < 8) - return false; + subjId = reader.readUuid("subjId"); - topVer = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 28: - UUID subjId0 = commState.getUuid(); + taskNameHash = reader.readInt("taskNameHash"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 29: - if (buf.remaining() < 4) - return false; + topVer = reader.readLong("topVer"); - taskNameHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -439,7 +390,7 @@ private Collection> cloneEntries(Collection invalidPartitions() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearTxPrepareResponse _clone = new GridNearTxPrepareResponse(); clone0(_clone); @@ -234,7 +234,7 @@ public Collection invalidPartitions() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridNearTxPrepareResponse _clone = (GridNearTxPrepareResponse)_msg; @@ -242,7 +242,7 @@ public Collection invalidPartitions() { _clone.pending = pending; _clone.futId = futId; _clone.miniId = miniId; - _clone.dhtVer = dhtVer; + _clone.dhtVer = dhtVer != null ? (GridCacheVersion)dhtVer.clone() : null; _clone.invalidParts = invalidParts; _clone.ownedVals = ownedVals; _clone.ownedValsBytes = ownedValsBytes; @@ -251,117 +251,54 @@ public Collection invalidPartitions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 10: - if (!commState.putCacheVersion(dhtVer)) + if (!writer.writeMessage("dhtVer", dhtVer)) return false; - commState.idx++; + state++; case 11: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 12: - if (invalidParts != null) { - if (commState.it == null) { - if (!commState.putInt(invalidParts.size())) - return false; - - commState.it = invalidParts.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putInt((int)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("invalidParts", invalidParts, int.class)) + return false; - commState.idx++; + state++; case 13: - if (!commState.putGridUuid(miniId)) + if (!writer.writeIgniteUuid("miniId", miniId)) return false; - commState.idx++; + state++; case 14: - if (ownedValsBytes != null) { - if (commState.it == null) { - if (!commState.putInt(ownedValsBytes.size())) - return false; - - commState.it = ownedValsBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("ownedValsBytes", ownedValsBytes, byte[].class)) + return false; - commState.idx++; + state++; case 15: - if (pending != null) { - if (commState.it == null) { - if (!commState.putInt(pending.size())) - return false; - - commState.it = pending.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("pending", pending, GridCacheVersion.class)) + return false; - commState.idx++; + state++; } @@ -371,128 +308,59 @@ public Collection invalidPartitions() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 10: - GridCacheVersion dhtVer0 = commState.getCacheVersion(); + dhtVer = reader.readMessage("dhtVer"); - if (dhtVer0 == CACHE_VER_NOT_READ) + if (!reader.isLastRead()) return false; - dhtVer = dhtVer0; - - commState.idx++; + state++; case 11: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 12: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (invalidParts == null) - invalidParts = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (buf.remaining() < 4) - return false; - - int _val = commState.getInt(); - - invalidParts.add((Integer)_val); - - commState.readItems++; - } - } + invalidParts = reader.readCollection("invalidParts", int.class); - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 13: - IgniteUuid miniId0 = commState.getGridUuid(); + miniId = reader.readIgniteUuid("miniId"); - if (miniId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - miniId = miniId0; - - commState.idx++; + state++; case 14: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (ownedValsBytes == null) - ownedValsBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; + ownedValsBytes = reader.readCollection("ownedValsBytes", byte[].class); - ownedValsBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 15: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (pending == null) - pending = new ArrayList<>(commState.readSize); + pending = reader.readCollection("pending", GridCacheVersion.class); - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - pending.add((GridCacheVersion)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -501,7 +369,7 @@ public Collection invalidPartitions() { /** {@inheritDoc} */ @Override public byte directType() { - return 55; + return 56; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java index 06ce651dfa9cf..267d798422d9c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java @@ -18,8 +18,8 @@ package org.apache.ignite.internal.processors.cache.distributed.near; import org.apache.ignite.internal.processors.cache.distributed.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -48,7 +48,7 @@ public GridNearUnlockRequest(int cacheId, int keyCnt) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridNearUnlockRequest _clone = new GridNearUnlockRequest(); clone0(_clone); @@ -57,7 +57,7 @@ public GridNearUnlockRequest(int cacheId, int keyCnt) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); } @@ -65,16 +65,16 @@ public GridNearUnlockRequest(int cacheId, int keyCnt) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } return true; @@ -83,7 +83,7 @@ public GridNearUnlockRequest(int cacheId, int keyCnt) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; @@ -93,7 +93,7 @@ public GridNearUnlockRequest(int cacheId, int keyCnt) { /** {@inheritDoc} */ @Override public byte directType() { - return 56; + return 57; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java index 7a8a11c004a71..dc3dabee737be 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java @@ -31,6 +31,7 @@ import javax.cache.*; import java.io.*; import java.util.*; +import java.util.concurrent.*; /** * Local cache implementation. @@ -196,6 +197,17 @@ public IgniteInternalFuture lockAllAsync(Collection keys, removeAll(keySet()); } + /** {@inheritDoc} */ + @Override public IgniteInternalFuture removeAllAsync() { + return ctx.closures().callLocalSafe(new Callable() { + @Override public Void call() throws Exception { + removeAll(); + + return null; + } + }); + } + /** {@inheritDoc} */ @Override public void onDeferredDelete(GridCacheEntryEx entry, GridCacheVersion ver) { assert false : "Should not be called"; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java index 54463738c12fd..d9f8e97271f03 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java @@ -464,6 +464,17 @@ public GridLocalAtomicCache(GridCacheContext ctx) { removeAll(keySet()); } + /** {@inheritDoc} */ + @Override public IgniteInternalFuture removeAllAsync() { + return ctx.closures().callLocalSafe(new Callable() { + @Override public Void call() throws Exception { + removeAll(); + + return null; + } + }); + } + /** {@inheritDoc} */ @Override public IgniteInternalFuture removeAllAsync(IgnitePredicate>[] filter) { return removeAllAsync(keySet(filter), filter); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java index 5f9c8beebbf57..df8e2c0af3970 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java @@ -20,11 +20,11 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.*; +import org.apache.ignite.plugin.extensions.communication.*; import javax.cache.*; import java.io.*; @@ -109,15 +109,12 @@ public class GridCacheQueryRequest extends GridCacheMessage implemen private boolean all; /** */ - @GridDirectVersion(1) private boolean keepPortable; /** */ - @GridDirectVersion(2) private UUID subjId; /** */ - @GridDirectVersion(2) private int taskHash; /** @@ -445,7 +442,7 @@ public int taskHash() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCacheQueryRequest _clone = new GridCacheQueryRequest(); clone0(_clone); @@ -454,7 +451,7 @@ public int taskHash() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCacheQueryRequest _clone = (GridCacheQueryRequest)_msg; @@ -488,132 +485,132 @@ public int taskHash() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (!commState.putBoolean(all)) + if (!writer.writeBoolean("all", all)) return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(argsBytes)) + if (!writer.writeByteArray("argsBytes", argsBytes)) return false; - commState.idx++; + state++; case 5: - if (!commState.putString(cacheName)) + if (!writer.writeString("cacheName", cacheName)) return false; - commState.idx++; + state++; case 6: - if (!commState.putBoolean(cancel)) + if (!writer.writeBoolean("cancel", cancel)) return false; - commState.idx++; + state++; case 7: - if (!commState.putString(clause)) + if (!writer.writeString("clause", clause)) return false; - commState.idx++; + state++; case 8: - if (!commState.putString(clsName)) + if (!writer.writeString("clsName", clsName)) return false; - commState.idx++; + state++; case 9: - if (!commState.putBoolean(fields)) + if (!writer.writeBoolean("fields", fields)) return false; - commState.idx++; + state++; case 10: - if (!commState.putLong(id)) + if (!writer.writeLong("id", id)) return false; - commState.idx++; + state++; case 11: - if (!commState.putBoolean(incBackups)) + if (!writer.writeBoolean("incBackups", incBackups)) return false; - commState.idx++; + state++; case 12: - if (!commState.putBoolean(incMeta)) + if (!writer.writeBoolean("incMeta", incMeta)) return false; - commState.idx++; + state++; case 13: - if (!commState.putByteArray(keyValFilterBytes)) + if (!writer.writeBoolean("keepPortable", keepPortable)) return false; - commState.idx++; + state++; case 14: - if (!commState.putInt(pageSize)) + if (!writer.writeByteArray("keyValFilterBytes", keyValFilterBytes)) return false; - commState.idx++; + state++; case 15: - if (!commState.putByteArray(prjFilterBytes)) + if (!writer.writeInt("pageSize", pageSize)) return false; - commState.idx++; + state++; case 16: - if (!commState.putByteArray(rdcBytes)) + if (!writer.writeByteArray("prjFilterBytes", prjFilterBytes)) return false; - commState.idx++; + state++; case 17: - if (!commState.putByteArray(transBytes)) + if (!writer.writeByteArray("rdcBytes", rdcBytes)) return false; - commState.idx++; + state++; case 18: - if (!commState.putEnum(type)) + if (!writer.writeUuid("subjId", subjId)) return false; - commState.idx++; + state++; case 19: - if (!commState.putBoolean(keepPortable)) + if (!writer.writeInt("taskHash", taskHash)) return false; - commState.idx++; + state++; case 20: - if (!commState.putUuid(subjId)) + if (!writer.writeByteArray("transBytes", transBytes)) return false; - commState.idx++; + state++; case 21: - if (!commState.putInt(taskHash)) + if (!writer.writeEnum("type", type)) return false; - commState.idx++; + state++; } @@ -623,183 +620,163 @@ public int taskHash() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (buf.remaining() < 1) - return false; + all = reader.readBoolean("all"); - all = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - byte[] argsBytes0 = commState.getByteArray(); + argsBytes = reader.readByteArray("argsBytes"); - if (argsBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - argsBytes = argsBytes0; - - commState.idx++; + state++; case 5: - String cacheName0 = commState.getString(); + cacheName = reader.readString("cacheName"); - if (cacheName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - cacheName = cacheName0; - - commState.idx++; + state++; case 6: - if (buf.remaining() < 1) - return false; + cancel = reader.readBoolean("cancel"); - cancel = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - String clause0 = commState.getString(); + clause = reader.readString("clause"); - if (clause0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - clause = clause0; - - commState.idx++; + state++; case 8: - String clsName0 = commState.getString(); + clsName = reader.readString("clsName"); - if (clsName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - clsName = clsName0; - - commState.idx++; + state++; case 9: - if (buf.remaining() < 1) - return false; + fields = reader.readBoolean("fields"); - fields = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 10: - if (buf.remaining() < 8) - return false; + id = reader.readLong("id"); - id = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 11: - if (buf.remaining() < 1) - return false; + incBackups = reader.readBoolean("incBackups"); - incBackups = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 12: - if (buf.remaining() < 1) - return false; + incMeta = reader.readBoolean("incMeta"); - incMeta = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 13: - byte[] keyValFilterBytes0 = commState.getByteArray(); + keepPortable = reader.readBoolean("keepPortable"); - if (keyValFilterBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - keyValFilterBytes = keyValFilterBytes0; - - commState.idx++; + state++; case 14: - if (buf.remaining() < 4) - return false; + keyValFilterBytes = reader.readByteArray("keyValFilterBytes"); - pageSize = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 15: - byte[] prjFilterBytes0 = commState.getByteArray(); + pageSize = reader.readInt("pageSize"); - if (prjFilterBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - prjFilterBytes = prjFilterBytes0; - - commState.idx++; + state++; case 16: - byte[] rdcBytes0 = commState.getByteArray(); + prjFilterBytes = reader.readByteArray("prjFilterBytes"); - if (rdcBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - rdcBytes = rdcBytes0; - - commState.idx++; + state++; case 17: - byte[] transBytes0 = commState.getByteArray(); + rdcBytes = reader.readByteArray("rdcBytes"); - if (transBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - transBytes = transBytes0; - - commState.idx++; + state++; case 18: - if (buf.remaining() < 1) - return false; + subjId = reader.readUuid("subjId"); - byte type0 = commState.getByte(); - - type = GridCacheQueryType.fromOrdinal(type0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 19: - if (buf.remaining() < 1) - return false; + taskHash = reader.readInt("taskHash"); - keepPortable = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 20: - UUID subjId0 = commState.getUuid(); + transBytes = reader.readByteArray("transBytes"); - if (subjId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - subjId = subjId0; - - commState.idx++; + state++; case 21: - if (buf.remaining() < 4) - return false; + type = reader.readEnum("type", GridCacheQueryType.class); - taskHash = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -808,7 +785,7 @@ public int taskHash() { /** {@inheritDoc} */ @Override public byte directType() { - return 57; + return 58; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java index 7a7b9b95e231d..acba6f69e521a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java @@ -21,10 +21,10 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.query.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -203,7 +203,7 @@ public boolean fields() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridCacheQueryResponse _clone = new GridCacheQueryResponse(); clone0(_clone); @@ -212,7 +212,7 @@ public boolean fields() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridCacheQueryResponse _clone = (GridCacheQueryResponse)_msg; @@ -231,96 +231,54 @@ public boolean fields() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 3: - if (dataBytes != null) { - if (commState.it == null) { - if (!commState.putInt(dataBytes.size())) - return false; - - commState.it = dataBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("dataBytes", dataBytes, byte[].class)) + return false; - commState.idx++; + state++; case 4: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 5: - if (!commState.putBoolean(fields)) + if (!writer.writeBoolean("fields", fields)) return false; - commState.idx++; + state++; case 6: - if (!commState.putBoolean(finished)) + if (!writer.writeBoolean("finished", finished)) return false; - commState.idx++; + state++; case 7: - if (metaDataBytes != null) { - if (commState.it == null) { - if (!commState.putInt(metaDataBytes.size())) - return false; - - commState.it = metaDataBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("metaDataBytes", metaDataBytes, byte[].class)) + return false; - commState.idx++; + state++; case 8: - if (!commState.putLong(reqId)) + if (!writer.writeLong("reqId", reqId)) return false; - commState.idx++; + state++; } @@ -330,103 +288,59 @@ public boolean fields() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 3: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (dataBytes == null) - dataBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - dataBytes.add((byte[])_val); + dataBytes = reader.readCollection("dataBytes", byte[].class); - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 5: - if (buf.remaining() < 1) - return false; + fields = reader.readBoolean("fields"); - fields = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 6: - if (buf.remaining() < 1) - return false; + finished = reader.readBoolean("finished"); - finished = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + metaDataBytes = reader.readCollection("metaDataBytes", byte[].class); - if (commState.readSize >= 0) { - if (metaDataBytes == null) - metaDataBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - metaDataBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 8: - if (buf.remaining() < 8) - return false; + reqId = reader.readLong("reqId"); - reqId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -435,7 +349,7 @@ public boolean fields() { /** {@inheritDoc} */ @Override public byte directType() { - return 58; + return 59; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/discovery/DiscoveryCallback.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/serialization/IgniteCacheSerializationManager.java similarity index 51% rename from modules/core/src/main/java/org/apache/ignite/plugin/extensions/discovery/DiscoveryCallback.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/serialization/IgniteCacheSerializationManager.java index 3ff848a1d870d..974cfd7b26e94 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/discovery/DiscoveryCallback.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/serialization/IgniteCacheSerializationManager.java @@ -15,37 +15,37 @@ * limitations under the License. */ -package org.apache.ignite.plugin.extensions.discovery; +package org.apache.ignite.internal.processors.cache.serialization; -import org.apache.ignite.cluster.*; -import org.apache.ignite.plugin.*; +import org.apache.ignite.internal.processors.cache.*; import java.util.*; /** - * Plugin extension that allows to listen messages from discovery. * - * TODO 9447: redesign. */ -public interface DiscoveryCallback extends Extension { +public interface IgniteCacheSerializationManager extends GridCacheManager { /** - * Handles node start. + * TODO this method should be removed from Ignite internals as a part of work on cache objects. * - * @param remoteNodes Remote grid nodes. + * @return Portable enabled flag for cache. */ - public void onStart(Collection remoteNodes); + public boolean portableEnabled(); /** - * Handles node joined event. - * - * @param node Joined node. + * @return {@code True} if portable format should be preserved when passing values to cache store. */ - public void beforeNodeJoined(ClusterNode node); + public boolean keepPortableInStore(); + + + public Object unwrapPortableIfNeeded(Object o, boolean keepPortable); /** - * Handles node left event. + * Unwraps collection. * - * @param node Left node. + * @param col Collection to unwrap. + * @param keepPortable Keep portable flag. + * @return Unwrapped collection. */ - public void onNodeLeft(ClusterNode node); + public Collection unwrapPortablesIfNeeded(Collection col, boolean keepPortable); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java index 01e06ba775b15..eb5e662d74776 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java @@ -1257,7 +1257,7 @@ public String resolveTaskName() { * @throws org.apache.ignite.IgniteCheckedException In case of eny exception. * @throws GridCacheEntryRemovedException If entry got removed. */ - protected IgniteBiTuple> conflictResolve( + protected IgniteBiTuple> conflictResolve( GridCacheOperation op, K key, V newVal, byte[] newValBytes, long newTtl, long newDrExpireTime, GridCacheVersion newVer, GridCacheEntryEx old) throws IgniteCheckedException, GridCacheEntryRemovedException { @@ -1271,9 +1271,9 @@ protected IgniteBiTuple= 0L ? newDrExpireTime : CU.toExpireTime(newTtl); GridCacheVersionedEntryEx newEntry = - new GridCachePlainVersionedEntry(key, newVal, newTtl, newExpireTime, newVer); + new GridCachePlainVersionedEntry<>(key, newVal, newTtl, newExpireTime, newVer); - GridCacheVersionConflictContextImpl ctx = old.context().conflictResolve(oldEntry, newEntry, false); + GridCacheVersionConflictContext ctx = old.context().conflictResolve(oldEntry, newEntry, false); if (ctx.isMerge()) { V resVal = ctx.mergeValue(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java index d1e26defcd659..4563ce10f51ca 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java @@ -33,7 +33,6 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.plugin.security.*; -import org.apache.ignite.portables.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; @@ -738,13 +737,13 @@ else if (cacheCtx.isNear() && txEntry.locallyMapped()) boolean drNeedResolve = cacheCtx.conflictNeedResolve(cached.version(), explicitVer); if (drNeedResolve) { - IgniteBiTuple> + IgniteBiTuple> drRes = conflictResolve(op, txEntry.key(), val, valBytes, txEntry.ttl(), txEntry.drExpireTime(), explicitVer, cached); assert drRes != null; - GridCacheVersionConflictContextImpl conflictCtx = drRes.get2(); + GridCacheVersionConflictContext conflictCtx = drRes.get2(); if (conflictCtx.isUseOld()) op = NOOP; @@ -2515,7 +2514,7 @@ else if (cacheCtx.portableEnabled()) { map0.put(key, val); } } - catch (PortableException e) { + catch (IgniteException e) { return new GridFinishedFuture<>(cctx.kernalContext(), e); } } @@ -2532,7 +2531,7 @@ else if (cacheCtx.portableEnabled()) { invokeMap0.put(key, e.getValue()); } } - catch (PortableException e) { + catch (IgniteException e) { return new GridFinishedFuture<>(cctx.kernalContext(), e); } } @@ -2736,7 +2735,7 @@ else if (cacheCtx.portableEnabled()) { else keys0 = null; } - catch (PortableException e) { + catch (IgniteException e) { return new GridFinishedFuture<>(cctx.kernalContext(), e); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java index 891af09f0907b..1990bb129cda4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java @@ -20,15 +20,18 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; +import java.nio.*; import java.util.*; /** * Grid unique version. */ -public class GridCacheVersion implements Comparable, Externalizable, OptimizedMarshallable { +public class GridCacheVersion extends MessageAdapter implements Comparable, Externalizable, + OptimizedMarshallable { /** */ private static final long serialVersionUID = 0L; @@ -249,6 +252,114 @@ public IgniteUuid asGridUuid() { return topologyVersion() < other.topologyVersion() ? -1 : 1; } + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf) { + writer.setBuffer(buf); + + if (!typeWritten) { + if (!writer.writeByte(null, directType())) + return false; + + typeWritten = true; + } + + switch (state) { + case 0: + if (!writer.writeLong("globalTime", globalTime)) + return false; + + state++; + + case 1: + if (!writer.writeInt("nodeOrderDrId", nodeOrderDrId)) + return false; + + state++; + + case 2: + if (!writer.writeLong("order", order)) + return false; + + state++; + + case 3: + if (!writer.writeInt("topVer", topVer)) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf) { + reader.setBuffer(buf); + + switch (state) { + case 0: + globalTime = reader.readLong("globalTime"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 1: + nodeOrderDrId = reader.readInt("nodeOrderDrId"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 2: + order = reader.readLong("order"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 3: + topVer = reader.readInt("topVer"); + + if (!reader.isLastRead()) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public byte directType() { + return 86; + } + + /** {@inheritDoc} */ + @SuppressWarnings("CloneDoesntCallSuperClone") + @Override public MessageAdapter clone() { + GridCacheVersion _clone = new GridCacheVersion(); + + clone0(_clone); + + return _clone; + } + + /** {@inheritDoc} */ + @Override protected void clone0(MessageAdapter _msg) { + GridCacheVersion _clone = (GridCacheVersion)_msg; + + _clone.topVer = topVer; + _clone.nodeOrderDrId = nodeOrderDrId; + _clone.globalTime = globalTime; + _clone.order = order; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridCacheVersion.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionAbstractConflictResolver.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionAbstractConflictResolver.java index a91bd4d3387e6..8bc6425cecf74 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionAbstractConflictResolver.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionAbstractConflictResolver.java @@ -32,9 +32,9 @@ public abstract class GridCacheVersionAbstractConflictResolver { * @return Conflict resolution context. * @throws IgniteCheckedException If failed. */ - public GridCacheVersionConflictContextImpl resolve(GridCacheVersionedEntryEx oldEntry, + public GridCacheVersionConflictContext resolve(GridCacheVersionedEntryEx oldEntry, GridCacheVersionedEntryEx newEntry, boolean atomicVerComparator) throws IgniteCheckedException { - GridCacheVersionConflictContextImpl ctx = new GridCacheVersionConflictContextImpl<>(oldEntry, newEntry); + GridCacheVersionConflictContext ctx = new GridCacheVersionConflictContext<>(oldEntry, newEntry); resolve0(ctx, oldEntry, newEntry, atomicVerComparator); @@ -50,7 +50,7 @@ public GridCacheVersionConflictContextImpl resolve(GridCacheVersion * @param atomicVerComparator Whether to use atomic version comparator. * @throws IgniteCheckedException If failed. */ - protected abstract void resolve0(GridCacheVersionConflictContextImpl ctx, + protected abstract void resolve0(GridCacheVersionConflictContext ctx, GridCacheVersionedEntryEx oldEntry, GridCacheVersionedEntryEx newEntry, boolean atomicVerComparator) throws IgniteCheckedException; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictContext.java index 1b5ef5ad3c546..b81380349205c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictContext.java @@ -17,36 +17,86 @@ package org.apache.ignite.internal.processors.cache.version; +import org.apache.ignite.internal.util.tostring.*; +import org.apache.ignite.internal.util.typedef.internal.*; import org.jetbrains.annotations.*; /** - * Cache version conflict context. + * Conflict context implementation. */ -public interface GridCacheVersionConflictContext { +public class GridCacheVersionConflictContext { + /** Old entry. */ + @GridToStringInclude + private final GridCacheVersionedEntry oldEntry; + + /** New entry. */ + @GridToStringInclude + private final GridCacheVersionedEntry newEntry; + + /** Current state. */ + private State state; + + /** Current merge value. */ + @GridToStringExclude + private V mergeVal; + + /** TTL. */ + private long ttl; + + /** Explicit TTL flag. */ + private boolean explicitTtl; + + /** Manual resolve flag. */ + private boolean manualResolve; + + /** + * Constructor. + * + * @param oldEntry Old entry. + * @param newEntry New entry. + */ + public GridCacheVersionConflictContext(GridCacheVersionedEntry oldEntry, + GridCacheVersionedEntry newEntry) { + assert oldEntry != null && newEntry != null; + assert oldEntry.ttl() >= 0 && newEntry.ttl() >= 0; + + this.oldEntry = oldEntry; + this.newEntry = newEntry; + + // Set initial state. + useNew(); + } + /** * Gets old (existing) cache entry. * * @return Old (existing) cache entry. */ - public GridCacheVersionedEntry oldEntry(); + public GridCacheVersionedEntry oldEntry() { + return oldEntry; + } /** * Gets new cache entry. * * @return New cache entry. */ - public GridCacheVersionedEntry newEntry(); + public GridCacheVersionedEntry newEntry() { + return newEntry; + } /** * Force cache to ignore new entry and leave old (existing) entry unchanged. */ - public void useOld(); + public void useOld() { + state = State.USE_OLD; + } /** * Force cache to apply new entry overwriting old (existing) entry. *

      * Note that updates from remote data centers always have explicit TTL , while local data center - * updates will only have explicit TTL in case {@link Entry#timeToLive(long)} was called + * updates will only have explicit TTL in case {@link CacheEntry#timeToLive(long)} was called * before update. In the latter case new entry will pick TTL of the old (existing) entry, even * if it was set through update from remote data center. it means that depending on concurrent * update timings new update might pick unexpected TTL. For example, consider that three updates @@ -57,7 +107,12 @@ public interface GridCacheVersionConflictContext { * update (3). To have predictable TTL in such cases you should either always set it explicitly * through {@code GridCacheEntry.timeToLive(long)} or use {@link #merge(Object, long)}. */ - public void useNew(); + public void useNew() { + state = State.USE_NEW; + + if (!explicitTtl) + ttl = newEntry.ttl(); + } /** * Force cache to use neither old, nor new, but some other value passed as argument. In this case old @@ -68,5 +123,97 @@ public interface GridCacheVersionConflictContext { * @param mergeVal Merge value or {@code null} to force remove. * @param ttl Time to live in milliseconds. */ - public void merge(@Nullable V mergeVal, long ttl); + public void merge(@Nullable V mergeVal, long ttl) { + state = State.MERGE; + + this.mergeVal = mergeVal; + this.ttl = ttl; + + explicitTtl = true; + } + + /** + * @return {@code True} in case old value should be used. + */ + public boolean isUseOld() { + return state == State.USE_OLD; + } + + /** + * @return {@code True} in case new value should be used. + */ + public boolean isUseNew() { + return state == State.USE_NEW; + } + + /** + * @return {@code True} in case merge is to be performed. + */ + public boolean isMerge() { + return state == State.MERGE; + } + + /** + * Set manual resolve class. + */ + public void manualResolve() { + this.manualResolve = true; + } + + /** + * @return Manual resolve flag. + */ + public boolean isManualResolve() { + return manualResolve; + } + + /** + * @return Value to merge (if any). + */ + @Nullable public V mergeValue() { + return mergeVal; + } + + /** + * @return TTL. + */ + public long ttl() { + return ttl; + } + + /** + * @return Expire time. + */ + public long expireTime() { + return explicitTtl ? CU.toExpireTime(ttl) : isUseNew() ? newEntry.expireTime() : + isUseOld() ? oldEntry.expireTime() : 0L; + } + + /** + * @return Explicit TTL flag. + */ + public boolean explicitTtl() { + return explicitTtl; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return state == State.MERGE ? + S.toString(GridCacheVersionConflictContext.class, this, "mergeValue", mergeVal) : + S.toString(GridCacheVersionConflictContext.class, this); + } + + /** + * State. + */ + private enum State { + /** Use old. */ + USE_OLD, + + /** Use new. */ + USE_NEW, + + /** Merge. */ + MERGE + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictContextImpl.java deleted file mode 100644 index ed901ecb49c98..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictContextImpl.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache.version; - -import org.apache.ignite.internal.util.tostring.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -/** - * Conflict context implementation. - */ -public class GridCacheVersionConflictContextImpl implements GridCacheVersionConflictContext { - /** Old entry. */ - @GridToStringInclude - private final GridCacheVersionedEntry oldEntry; - - /** New entry. */ - @GridToStringInclude - private final GridCacheVersionedEntry newEntry; - - /** Current state. */ - private State state; - - /** Current merge value. */ - @GridToStringExclude - private V mergeVal; - - /** TTL. */ - private long ttl; - - /** Explicit TTL flag. */ - private boolean explicitTtl; - - /** Manual resolve flag. */ - private boolean manualResolve; - - /** - * Constructor. - * - * @param oldEntry Old entry. - * @param newEntry New entry. - */ - public GridCacheVersionConflictContextImpl(GridCacheVersionedEntry oldEntry, - GridCacheVersionedEntry newEntry) { - assert oldEntry != null && newEntry != null; - assert oldEntry.ttl() >= 0 && newEntry.ttl() >= 0; - - this.oldEntry = oldEntry; - this.newEntry = newEntry; - - // Set initial state. - useNew(); - } - - /** {@inheritDoc} */ - @Override public GridCacheVersionedEntry oldEntry() { - return oldEntry; - } - - /** {@inheritDoc} */ - @Override public GridCacheVersionedEntry newEntry() { - return newEntry; - } - - /** {@inheritDoc} */ - @Override public void useOld() { - state = State.USE_OLD; - } - - /** {@inheritDoc} */ - @Override public void useNew() { - state = State.USE_NEW; - - if (!explicitTtl) - ttl = newEntry.ttl(); - } - - /** {@inheritDoc} */ - @Override public void merge(@Nullable V mergeVal, long ttl) { - state = State.MERGE; - - this.mergeVal = mergeVal; - this.ttl = ttl; - - explicitTtl = true; - } - - /** - * @return {@code True} in case old value should be used. - */ - public boolean isUseOld() { - return state == State.USE_OLD; - } - - /** - * @return {@code True} in case new value should be used. - */ - public boolean isUseNew() { - return state == State.USE_NEW; - } - - /** - * @return {@code True} in case merge is to be performed. - */ - public boolean isMerge() { - return state == State.MERGE; - } - - /** - * Set manual resolve class. - */ - public void manualResolve() { - this.manualResolve = true; - } - - /** - * @return Manual resolve flag. - */ - public boolean isManualResolve() { - return manualResolve; - } - - /** - * @return Value to merge (if any). - */ - @Nullable public V mergeValue() { - return mergeVal; - } - - /** - * @return TTL. - */ - public long ttl() { - return ttl; - } - - /** - * @return Expire time. - */ - public long expireTime() { - return explicitTtl ? CU.toExpireTime(ttl) : isUseNew() ? newEntry.expireTime() : - isUseOld() ? oldEntry.expireTime() : 0L; - } - - /** - * @return Explicit TTL flag. - */ - public boolean explicitTtl() { - return explicitTtl; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return state == State.MERGE ? - S.toString(GridCacheVersionConflictContextImpl.class, this, "mergeValue", mergeVal) : - S.toString(GridCacheVersionConflictContextImpl.class, this); - } - - /** - * State. - */ - private enum State { - /** Use old. */ - USE_OLD, - - /** Use new. */ - USE_NEW, - - /** Merge. */ - MERGE - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictResolver.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictResolver.java index e327fb9e6d4a6..869993cf84538 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictResolver.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionConflictResolver.java @@ -25,7 +25,7 @@ */ public class GridCacheVersionConflictResolver extends GridCacheVersionAbstractConflictResolver { /** {@inheritDoc} */ - @Override protected void resolve0(GridCacheVersionConflictContextImpl ctx, + @Override protected void resolve0(GridCacheVersionConflictContext ctx, GridCacheVersionedEntryEx oldEntry, GridCacheVersionedEntryEx newEntry, boolean atomicVerComparator) throws IgniteCheckedException { if (newEntry.dataCenterId() != oldEntry.dataCenterId()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshotMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshotMessage.java index 89b145f980e5d..5afd5a8585aa5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshotMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshotMessage.java @@ -18,9 +18,9 @@ package org.apache.ignite.internal.processors.clock; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -29,7 +29,7 @@ /** * Message containing time delta map for all nodes. */ -public class GridClockDeltaSnapshotMessage extends GridTcpCommunicationMessageAdapter { +public class GridClockDeltaSnapshotMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -73,7 +73,7 @@ public Map deltas() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridClockDeltaSnapshotMessage _clone = new GridClockDeltaSnapshotMessage(); clone0(_clone); @@ -82,69 +82,37 @@ public Map deltas() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridClockDeltaSnapshotMessage _clone = (GridClockDeltaSnapshotMessage)_msg; - _clone.snapVer = snapVer; + _clone.snapVer = snapVer != null ? (GridClockDeltaVersion)snapVer.clone() : null; _clone.deltas = deltas; } /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (deltas != null) { - if (commState.it == null) { - if (!commState.putInt(deltas.size())) - return false; - - commState.it = deltas.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putUuid(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putLong(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("deltas", deltas, UUID.class, long.class)) + return false; - commState.idx++; + state++; case 1: - if (!commState.putClockDeltaVersion(snapVer)) + if (!writer.writeMessage("snapVer", snapVer)) return false; - commState.idx++; + state++; } @@ -154,60 +122,24 @@ public Map deltas() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } + deltas = reader.readMap("deltas", UUID.class, long.class, false); - if (commState.readSize >= 0) { - if (deltas == null) - deltas = U.newHashMap(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } - - if (buf.remaining() < 8) - return false; - - long _val = commState.getLong(); - - deltas.put((UUID)commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 1: - GridClockDeltaVersion snapVer0 = commState.getClockDeltaVersion(); + snapVer = reader.readMessage("snapVer"); - if (snapVer0 == CLOCK_DELTA_VER_NOT_READ) + if (!reader.isLastRead()) return false; - snapVer = snapVer0; - - commState.idx++; + state++; } @@ -216,7 +148,7 @@ public Map deltas() { /** {@inheritDoc} */ @Override public byte directType() { - return 59; + return 60; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java index aa03c88801fb1..993213230ea3a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java @@ -18,13 +18,15 @@ package org.apache.ignite.internal.processors.clock; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; +import java.nio.*; /** * Version for time delta snapshot. */ -public class GridClockDeltaVersion implements Comparable, Externalizable { +public class GridClockDeltaVersion extends MessageAdapter implements Comparable, Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -110,6 +112,84 @@ public long topologyVersion() { topVer = in.readLong(); } + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf) { + writer.setBuffer(buf); + + if (!typeWritten) { + if (!writer.writeByte(null, directType())) + return false; + + typeWritten = true; + } + + switch (state) { + case 0: + if (!writer.writeLong("topVer", topVer)) + return false; + + state++; + + case 1: + if (!writer.writeLong("ver", ver)) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf) { + reader.setBuffer(buf); + + switch (state) { + case 0: + topVer = reader.readLong("topVer"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 1: + ver = reader.readLong("ver"); + + if (!reader.isLastRead()) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public byte directType() { + return 83; + } + + /** {@inheritDoc} */ + @SuppressWarnings("CloneDoesntCallSuperClone") + @Override public MessageAdapter clone() { + GridClockDeltaVersion _clone = new GridClockDeltaVersion(); + + clone0(_clone); + + return _clone; + } + + /** {@inheritDoc} */ + @Override protected void clone0(MessageAdapter _msg) { + GridClockDeltaVersion _clone = (GridClockDeltaVersion)_msg; + + _clone.ver = ver; + _clone.topVer = topVer; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridClockDeltaVersion.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousMessage.java index bfa95329711a2..e005a9b30197b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousMessage.java @@ -18,10 +18,10 @@ package org.apache.ignite.internal.processors.continuous; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -33,7 +33,7 @@ /** * Continuous processor message. */ -public class GridContinuousMessage extends GridTcpCommunicationMessageAdapter { +public class GridContinuousMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -132,7 +132,7 @@ public void dataBytes(byte[] dataBytes) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridContinuousMessage _clone = new GridContinuousMessage(); clone0(_clone); @@ -141,52 +141,52 @@ public void dataBytes(byte[] dataBytes) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter msg) { - GridContinuousMessage clone = (GridContinuousMessage)msg; - - clone.type = type; - clone.routineId = routineId; - clone.futId = futId; - clone.data = data; - clone.dataBytes = dataBytes; + @Override protected void clone0(MessageAdapter _msg) { + GridContinuousMessage _clone = (GridContinuousMessage)_msg; + + _clone.type = type; + _clone.routineId = routineId; + _clone.data = data; + _clone.dataBytes = dataBytes; + _clone.futId = futId; } /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(dataBytes)) + if (!writer.writeByteArray("dataBytes", dataBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putUuid(routineId)) + if (!writer.writeUuid("routineId", routineId)) return false; - commState.idx++; + state++; case 3: - if (!commState.putEnum(type)) + if (!writer.writeEnum("type", type)) return false; - commState.idx++; + state++; } @@ -196,48 +196,40 @@ public void dataBytes(byte[] dataBytes) { /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - byte[] dataBytes0 = commState.getByteArray(); + dataBytes = reader.readByteArray("dataBytes"); - if (dataBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - dataBytes = dataBytes0; - - commState.idx++; + state++; case 1: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; case 2: - UUID routineId0 = commState.getUuid(); + routineId = reader.readUuid("routineId"); - if (routineId0 == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - routineId = routineId0; - - commState.idx++; + state++; case 3: - if (buf.remaining() < 1) - return false; - - byte type0 = commState.getByte(); + type = reader.readEnum("type", GridContinuousMessageType.class); - type = fromOrdinal(type0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -246,7 +238,7 @@ public void dataBytes(byte[] dataBytes) { /** {@inheritDoc} */ @Override public byte directType() { - return 60; + return 61; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java index 1fd957111733e..bf24a85438539 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java @@ -1132,13 +1132,7 @@ private void sendWithRetries(Collection nodes, GridContin if (msg.data() != null && (nodes.size() > 1 || !ctx.localNodeId().equals(F.first(nodes).id()))) msg.dataBytes(marsh.marshal(msg.data())); - boolean first = true; - for (ClusterNode node : nodes) { - msg = first ? msg : (GridContinuousMessage)msg.clone(); - - first = false; - int cnt = 0; while (cnt <= retryCnt) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/GridDataLoadRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/GridDataLoadRequest.java index d49906f1577c8..169fe46c7192a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/GridDataLoadRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/GridDataLoadRequest.java @@ -19,10 +19,10 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.nio.*; @@ -31,7 +31,7 @@ /** * */ -public class GridDataLoadRequest extends GridTcpCommunicationMessageAdapter { +public class GridDataLoadRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -224,125 +224,93 @@ public boolean forceLocalDeployment() { /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putString(cacheName)) + if (!writer.writeString("cacheName", cacheName)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(clsLdrId)) + if (!writer.writeIgniteUuid("clsLdrId", clsLdrId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putByteArray(colBytes)) + if (!writer.writeByteArray("colBytes", colBytes)) return false; - commState.idx++; + state++; case 3: - if (!commState.putEnum(depMode)) + if (!writer.writeEnum("depMode", depMode)) return false; - commState.idx++; + state++; case 4: - if (!commState.putBoolean(forceLocDep)) + if (!writer.writeBoolean("forceLocDep", forceLocDep)) return false; - commState.idx++; + state++; case 5: - if (!commState.putBoolean(ignoreDepOwnership)) + if (!writer.writeBoolean("ignoreDepOwnership", ignoreDepOwnership)) return false; - commState.idx++; + state++; case 6: - if (ldrParticipants != null) { - if (commState.it == null) { - if (!commState.putInt(ldrParticipants.size())) - return false; - - commState.it = ldrParticipants.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putUuid(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putGridUuid(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("ldrParticipants", ldrParticipants, UUID.class, IgniteUuid.class)) + return false; - commState.idx++; + state++; case 7: - if (!commState.putLong(reqId)) + if (!writer.writeLong("reqId", reqId)) return false; - commState.idx++; + state++; case 8: - if (!commState.putByteArray(resTopicBytes)) + if (!writer.writeByteArray("resTopicBytes", resTopicBytes)) return false; - commState.idx++; + state++; case 9: - if (!commState.putString(sampleClsName)) + if (!writer.writeString("sampleClsName", sampleClsName)) return false; - commState.idx++; + state++; case 10: - if (!commState.putBoolean(skipStore)) + if (!writer.writeBoolean("skipStore", skipStore)) return false; - commState.idx++; + state++; case 11: - if (!commState.putByteArray(updaterBytes)) + if (!writer.writeByteArray("updaterBytes", updaterBytes)) return false; - commState.idx++; + state++; case 12: - if (!commState.putString(userVer)) + if (!writer.writeString("userVer", userVer)) return false; - commState.idx++; + state++; } @@ -351,162 +319,112 @@ public boolean forceLocalDeployment() { /** {@inheritDoc} */ @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - String cacheName0 = commState.getString(); + cacheName = reader.readString("cacheName"); - if (cacheName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - cacheName = cacheName0; - - commState.idx++; + state++; case 1: - IgniteUuid clsLdrId0 = commState.getGridUuid(); + clsLdrId = reader.readIgniteUuid("clsLdrId"); - if (clsLdrId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - clsLdrId = clsLdrId0; - - commState.idx++; + state++; case 2: - byte[] colBytes0 = commState.getByteArray(); + colBytes = reader.readByteArray("colBytes"); - if (colBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - colBytes = colBytes0; - - commState.idx++; + state++; case 3: - if (buf.remaining() < 1) - return false; - - byte depMode0 = commState.getByte(); + depMode = reader.readEnum("depMode", DeploymentMode.class); - depMode = DeploymentMode.fromOrdinal(depMode0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (buf.remaining() < 1) - return false; + forceLocDep = reader.readBoolean("forceLocDep"); - forceLocDep = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - if (buf.remaining() < 1) - return false; + ignoreDepOwnership = reader.readBoolean("ignoreDepOwnership"); - ignoreDepOwnership = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 6: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; + ldrParticipants = reader.readMap("ldrParticipants", UUID.class, IgniteUuid.class, false); - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (ldrParticipants == null) - ldrParticipants = new HashMap<>(commState.readSize, 1.0f); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } - - IgniteUuid _val = commState.getGridUuid(); - - if (_val == GRID_UUID_NOT_READ) - return false; - - ldrParticipants.put((UUID)commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 7: - if (buf.remaining() < 8) - return false; + reqId = reader.readLong("reqId"); - reqId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 8: - byte[] resTopicBytes0 = commState.getByteArray(); + resTopicBytes = reader.readByteArray("resTopicBytes"); - if (resTopicBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - resTopicBytes = resTopicBytes0; - - commState.idx++; + state++; case 9: - String sampleClsName0 = commState.getString(); + sampleClsName = reader.readString("sampleClsName"); - if (sampleClsName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - sampleClsName = sampleClsName0; - - commState.idx++; + state++; case 10: - if (buf.remaining() < 1) - return false; + skipStore = reader.readBoolean("skipStore"); - skipStore = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 11: - byte[] updaterBytes0 = commState.getByteArray(); + updaterBytes = reader.readByteArray("updaterBytes"); - if (updaterBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - updaterBytes = updaterBytes0; - - commState.idx++; + state++; case 12: - String userVer0 = commState.getString(); + userVer = reader.readString("userVer"); - if (userVer0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - userVer = userVer0; - - commState.idx++; + state++; } @@ -515,11 +433,11 @@ public boolean forceLocalDeployment() { /** {@inheritDoc} */ @Override public byte directType() { - return 61; + return 62; } /** {@inheritDoc} */ - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDataLoadRequest _clone = new GridDataLoadRequest(); clone0(_clone); @@ -528,7 +446,7 @@ public boolean forceLocalDeployment() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridDataLoadRequest _clone = (GridDataLoadRequest)_msg; _clone.reqId = reqId; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/GridDataLoadResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/GridDataLoadResponse.java index 6f784f5ecb15e..8676e7e3a83f5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/GridDataLoadResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/GridDataLoadResponse.java @@ -17,15 +17,15 @@ package org.apache.ignite.internal.processors.dataload; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.nio.*; /** * */ -public class GridDataLoadResponse extends GridTcpCommunicationMessageAdapter { +public class GridDataLoadResponse extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -84,7 +84,7 @@ public boolean forceLocalDeployment() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridDataLoadResponse _clone = new GridDataLoadResponse(); clone0(_clone); @@ -93,7 +93,7 @@ public boolean forceLocalDeployment() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridDataLoadResponse _clone = (GridDataLoadResponse)_msg; _clone.reqId = reqId; @@ -104,33 +104,33 @@ public boolean forceLocalDeployment() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putBoolean(forceLocDep)) + if (!writer.writeBoolean("forceLocDep", forceLocDep)) return false; - commState.idx++; + state++; case 2: - if (!commState.putLong(reqId)) + if (!writer.writeLong("reqId", reqId)) return false; - commState.idx++; + state++; } @@ -140,34 +140,32 @@ public boolean forceLocalDeployment() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 1: - if (buf.remaining() < 1) - return false; + forceLocDep = reader.readBoolean("forceLocDep"); - forceLocDep = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - if (buf.remaining() < 8) - return false; + reqId = reader.readLong("reqId"); - reqId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -176,6 +174,6 @@ public boolean forceLocalDeployment() { /** {@inheritDoc} */ @Override public byte directType() { - return 62; + return 63; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/IgniteDataLoaderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/IgniteDataLoaderImpl.java index ca9d1a1893695..c7002f8c91654 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/IgniteDataLoaderImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/dataload/IgniteDataLoaderImpl.java @@ -176,11 +176,7 @@ public IgniteDataLoaderImpl( if (node == null) throw new IllegalStateException("Cache doesn't exist: " + cacheName); - GridCacheAttributes attrs = U.cacheAttributes(node, cacheName); - - assert attrs != null : cacheName; - - portableEnabled = attrs.portableEnabled(); + portableEnabled = ctx.portable().portableEnabled(node, cacheName); discoLsnr = new GridLocalEventListener() { @Override public void onEvent(Event evt) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAckMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAckMessage.java index 949fa7bf47f5f..6bbb8e41757ca 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAckMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAckMessage.java @@ -19,9 +19,9 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -104,7 +104,7 @@ public IgniteCheckedException error() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridGgfsAckMessage _clone = new GridGgfsAckMessage(); clone0(_clone); @@ -113,7 +113,7 @@ public IgniteCheckedException error() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridGgfsAckMessage _clone = (GridGgfsAckMessage)_msg; @@ -127,36 +127,36 @@ public IgniteCheckedException error() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(fileId)) + if (!writer.writeIgniteUuid("fileId", fileId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putLong(id)) + if (!writer.writeLong("id", id)) return false; - commState.idx++; + state++; } @@ -166,39 +166,35 @@ public IgniteCheckedException error() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 0: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 1: - IgniteUuid fileId0 = commState.getGridUuid(); + fileId = reader.readIgniteUuid("fileId"); - if (fileId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - fileId = fileId0; - - commState.idx++; + state++; case 2: - if (buf.remaining() < 8) - return false; + id = reader.readLong("id"); - id = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -207,6 +203,6 @@ public IgniteCheckedException error() { /** {@inheritDoc} */ @Override public byte directType() { - return 65; + return 64; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsBlockKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsBlockKey.java index 2e877bdfc80a6..6fc3776ad1748 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsBlockKey.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsBlockKey.java @@ -18,10 +18,10 @@ package org.apache.ignite.internal.processors.fs; import org.apache.ignite.internal.processors.task.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -31,7 +31,7 @@ * File's binary data block key. */ @GridInternal -public final class GridGgfsBlockKey extends GridTcpCommunicationMessageAdapter +public final class GridGgfsBlockKey extends MessageAdapter implements Externalizable, Comparable { /** */ private static final long serialVersionUID = 0L; @@ -160,7 +160,7 @@ public long getBlockId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridGgfsBlockKey _clone = new GridGgfsBlockKey(); clone0(_clone); @@ -169,7 +169,7 @@ public long getBlockId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridGgfsBlockKey _clone = (GridGgfsBlockKey)_msg; _clone.fileId = fileId; @@ -181,39 +181,39 @@ public long getBlockId() { /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(affKey)) + if (!writer.writeIgniteUuid("affKey", affKey)) return false; - commState.idx++; + state++; case 1: - if (!commState.putLong(blockId)) + if (!writer.writeLong("blockId", blockId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putBoolean(evictExclude)) + if (!writer.writeBoolean("evictExclude", evictExclude)) return false; - commState.idx++; + state++; case 3: - if (!commState.putGridUuid(fileId)) + if (!writer.writeIgniteUuid("fileId", fileId)) return false; - commState.idx++; + state++; } @@ -223,44 +223,40 @@ public long getBlockId() { /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid affKey0 = commState.getGridUuid(); + affKey = reader.readIgniteUuid("affKey"); - if (affKey0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - affKey = affKey0; - - commState.idx++; + state++; case 1: - if (buf.remaining() < 8) - return false; + blockId = reader.readLong("blockId"); - blockId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - if (buf.remaining() < 1) - return false; + evictExclude = reader.readBoolean("evictExclude"); - evictExclude = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - IgniteUuid fileId0 = commState.getGridUuid(); + fileId = reader.readIgniteUuid("fileId"); - if (fileId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - fileId = fileId0; - - commState.idx++; + state++; } @@ -269,7 +265,7 @@ public long getBlockId() { /** {@inheritDoc} */ @Override public byte directType() { - return 66; + return 65; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsBlocksMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsBlocksMessage.java index 74684a8996b78..a99de9f67ab8a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsBlocksMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsBlocksMessage.java @@ -18,9 +18,8 @@ package org.apache.ignite.internal.processors.fs; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -86,7 +85,7 @@ public Map blocks() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridGgfsBlocksMessage _clone = new GridGgfsBlocksMessage(); clone0(_clone); @@ -95,7 +94,7 @@ public Map blocks() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridGgfsBlocksMessage _clone = (GridGgfsBlocksMessage)_msg; @@ -108,68 +107,36 @@ public Map blocks() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (blocks != null) { - if (commState.it == null) { - if (!commState.putInt(blocks.size())) - return false; - - commState.it = blocks.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putMessage(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putByteArray(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("blocks", blocks, GridGgfsBlockKey.class, byte[].class)) + return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(fileId)) + if (!writer.writeIgniteUuid("fileId", fileId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putLong(id)) + if (!writer.writeLong("id", id)) return false; - commState.idx++; + state++; } @@ -179,71 +146,35 @@ public Map blocks() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 0: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (blocks == null) - blocks = U.newHashMap(commState.readSize); + blocks = reader.readMap("blocks", GridGgfsBlockKey.class, byte[].class, false); - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - Object _val = commState.getMessage(); - - if (_val == MSG_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } - - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - blocks.put((GridGgfsBlockKey)commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 1: - IgniteUuid fileId0 = commState.getGridUuid(); + fileId = reader.readIgniteUuid("fileId"); - if (fileId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - fileId = fileId0; - - commState.idx++; + state++; case 2: - if (buf.remaining() < 8) - return false; + id = reader.readLong("id"); - id = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -252,6 +183,6 @@ public Map blocks() { /** {@inheritDoc} */ @Override public byte directType() { - return 67; + return 66; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsCommunicationMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsCommunicationMessage.java index 1e5d4df7d0c1b..860eb4c1f1ed3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsCommunicationMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsCommunicationMessage.java @@ -18,8 +18,8 @@ package org.apache.ignite.internal.processors.fs; import org.apache.ignite.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.marshaller.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.nio.*; @@ -27,12 +27,12 @@ /** * Base class for all GGFS communication messages sent between nodes. */ -public abstract class GridGgfsCommunicationMessage extends GridTcpCommunicationMessageAdapter { +public abstract class GridGgfsCommunicationMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { } /** @@ -54,13 +54,13 @@ public void finishUnmarshal(Marshaller marsh, @Nullable ClassLoader ldr) throws /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } return true; @@ -68,7 +68,7 @@ public void finishUnmarshal(Marshaller marsh, @Nullable ClassLoader ldr) throws /** {@inheritDoc} */ @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); return true; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsDeleteMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsDeleteMessage.java index 2d788cc3028f6..18ae5b53a405a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsDeleteMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsDeleteMessage.java @@ -19,10 +19,10 @@ import org.apache.ignite.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -108,7 +108,7 @@ public IgniteCheckedException error() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridGgfsDeleteMessage _clone = new GridGgfsDeleteMessage(); clone0(_clone); @@ -117,7 +117,7 @@ public IgniteCheckedException error() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridGgfsDeleteMessage _clone = (GridGgfsDeleteMessage)_msg; @@ -130,30 +130,30 @@ public IgniteCheckedException error() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(id)) + if (!writer.writeIgniteUuid("id", id)) return false; - commState.idx++; + state++; } @@ -163,31 +163,27 @@ public IgniteCheckedException error() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 0: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 1: - IgniteUuid id0 = commState.getGridUuid(); + id = reader.readIgniteUuid("id"); - if (id0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - id = id0; - - commState.idx++; + state++; } @@ -196,7 +192,7 @@ public IgniteCheckedException error() { /** {@inheritDoc} */ @Override public byte directType() { - return 68; + return 67; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsDeleteWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsDeleteWorker.java index f0eabc67a25be..18424034574a3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsDeleteWorker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsDeleteWorker.java @@ -332,15 +332,9 @@ private void sendDeleteMessage(GridGgfsDeleteMessage msg) { Collection nodes = meta.metaCacheNodes(); - boolean first = true; - for (ClusterNode node : nodes) { - GridGgfsCommunicationMessage msg0 = first ? msg : (GridGgfsCommunicationMessage)msg.clone(); - - first = false; - try { - ggfsCtx.send(node, topic, msg0, GridIoPolicy.SYSTEM_POOL); + ggfsCtx.send(node, topic, msg, GridIoPolicy.SYSTEM_POOL); } catch (IgniteCheckedException e) { U.warn(log, "Failed to send GGFS delete message to node [nodeId=" + node.id() + diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFileAffinityRange.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFileAffinityRange.java index 91e32468f08bc..edd9d6a74843b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFileAffinityRange.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFileAffinityRange.java @@ -17,10 +17,10 @@ package org.apache.ignite.internal.processors.fs; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -30,7 +30,7 @@ /** * Affinity range. */ -public class GridGgfsFileAffinityRange extends GridTcpCommunicationMessageAdapter implements Externalizable { +public class GridGgfsFileAffinityRange extends MessageAdapter implements Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -264,7 +264,7 @@ public boolean regionEqual(GridGgfsFileAffinityRange other) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridGgfsFileAffinityRange _clone = new GridGgfsFileAffinityRange(); clone0(_clone); @@ -273,7 +273,7 @@ public boolean regionEqual(GridGgfsFileAffinityRange other) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridGgfsFileAffinityRange _clone = (GridGgfsFileAffinityRange)_msg; _clone.affKey = affKey; @@ -286,45 +286,45 @@ public boolean regionEqual(GridGgfsFileAffinityRange other) { /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(affKey)) + if (!writer.writeIgniteUuid("affKey", affKey)) return false; - commState.idx++; + state++; case 1: - if (!commState.putBoolean(done)) + if (!writer.writeBoolean("done", done)) return false; - commState.idx++; + state++; case 2: - if (!commState.putLong(endOff)) + if (!writer.writeLong("endOff", endOff)) return false; - commState.idx++; + state++; case 3: - if (!commState.putLong(startOff)) + if (!writer.writeLong("startOff", startOff)) return false; - commState.idx++; + state++; case 4: - if (!commState.putInt(status)) + if (!writer.writeInt("status", status)) return false; - commState.idx++; + state++; } @@ -334,50 +334,48 @@ public boolean regionEqual(GridGgfsFileAffinityRange other) { /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid affKey0 = commState.getGridUuid(); + affKey = reader.readIgniteUuid("affKey"); - if (affKey0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - affKey = affKey0; - - commState.idx++; + state++; case 1: - if (buf.remaining() < 1) - return false; + done = reader.readBoolean("done"); - done = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - if (buf.remaining() < 8) - return false; + endOff = reader.readLong("endOff"); - endOff = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - if (buf.remaining() < 8) - return false; + startOff = reader.readLong("startOff"); - startOff = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (buf.remaining() < 4) - return false; + status = reader.readInt("status"); - status = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -386,7 +384,7 @@ public boolean regionEqual(GridGgfsFileAffinityRange other) { /** {@inheritDoc} */ @Override public byte directType() { - return 69; + return 68; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFragmentizerRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFragmentizerRequest.java index 5b6bdb1535bd7..978a2d66a8ec9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFragmentizerRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFragmentizerRequest.java @@ -18,10 +18,10 @@ package org.apache.ignite.internal.processors.fs; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -80,7 +80,7 @@ public Collection fragmentRanges() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridGgfsFragmentizerRequest _clone = new GridGgfsFragmentizerRequest(); clone0(_clone); @@ -89,7 +89,7 @@ public Collection fragmentRanges() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridGgfsFragmentizerRequest _clone = (GridGgfsFragmentizerRequest)_msg; @@ -101,51 +101,30 @@ public Collection fragmentRanges() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(fileId)) + if (!writer.writeIgniteUuid("fileId", fileId)) return false; - commState.idx++; + state++; case 1: - if (fragmentRanges != null) { - if (commState.it == null) { - if (!commState.putInt(fragmentRanges.size())) - return false; - - commState.it = fragmentRanges.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putMessage((GridGgfsFileAffinityRange)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeCollection("fragmentRanges", fragmentRanges, GridGgfsFileAffinityRange.class)) + return false; - commState.idx++; + state++; } @@ -155,50 +134,27 @@ public Collection fragmentRanges() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid fileId0 = commState.getGridUuid(); + fileId = reader.readIgniteUuid("fileId"); - if (fileId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - fileId = fileId0; - - commState.idx++; + state++; case 1: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; + fragmentRanges = reader.readCollection("fragmentRanges", GridGgfsFileAffinityRange.class); - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (fragmentRanges == null) - fragmentRanges = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - Object _val = commState.getMessage(); - - if (_val == MSG_NOT_READ) - return false; - - fragmentRanges.add((GridGgfsFileAffinityRange)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -207,6 +163,6 @@ public Collection fragmentRanges() { /** {@inheritDoc} */ @Override public byte directType() { - return 70; + return 69; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFragmentizerResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFragmentizerResponse.java index 087e4278e2ac0..5a90b3c7c60d0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFragmentizerResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsFragmentizerResponse.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.processors.fs; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -56,7 +56,7 @@ public IgniteUuid fileId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridGgfsFragmentizerResponse _clone = new GridGgfsFragmentizerResponse(); clone0(_clone); @@ -65,7 +65,7 @@ public IgniteUuid fileId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridGgfsFragmentizerResponse _clone = (GridGgfsFragmentizerResponse)_msg; @@ -76,24 +76,24 @@ public IgniteUuid fileId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(fileId)) + if (!writer.writeIgniteUuid("fileId", fileId)) return false; - commState.idx++; + state++; } @@ -103,21 +103,19 @@ public IgniteUuid fileId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid fileId0 = commState.getGridUuid(); + fileId = reader.readIgniteUuid("fileId"); - if (fileId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - fileId = fileId0; - - commState.idx++; + state++; } @@ -126,6 +124,6 @@ public IgniteUuid fileId() { /** {@inheritDoc} */ @Override public byte directType() { - return 71; + return 70; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsSyncMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsSyncMessage.java index 1f17b7e7e8cca..c7c1e77053684 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsSyncMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsSyncMessage.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.processors.fs; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -73,7 +73,7 @@ public boolean response() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridGgfsSyncMessage _clone = new GridGgfsSyncMessage(); clone0(_clone); @@ -82,7 +82,7 @@ public boolean response() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { super.clone0(_msg); GridGgfsSyncMessage _clone = (GridGgfsSyncMessage)_msg; @@ -94,30 +94,30 @@ public boolean response() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); if (!super.writeTo(buf)) return false; - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putLong(order)) + if (!writer.writeLong("order", order)) return false; - commState.idx++; + state++; case 1: - if (!commState.putBoolean(res)) + if (!writer.writeBoolean("res", res)) return false; - commState.idx++; + state++; } @@ -127,27 +127,27 @@ public boolean response() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); if (!super.readFrom(buf)) return false; - switch (commState.idx) { + switch (state) { case 0: - if (buf.remaining() < 8) - return false; + order = reader.readLong("order"); - order = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 1: - if (buf.remaining() < 1) - return false; + res = reader.readBoolean("res"); - res = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -156,6 +156,6 @@ public boolean response() { /** {@inheritDoc} */ @Override public byte directType() { - return 72; + return 71; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/IgniteFsProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/IgniteFsProcessor.java index d6cae0603bcc2..aee707c4a560b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/IgniteFsProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/IgniteFsProcessor.java @@ -28,7 +28,6 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.license.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.ipc.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -80,43 +79,6 @@ public IgniteFsProcessor(GridKernalContext ctx) { assert cfgs != null && cfgs.length > 0; - // Register GGFS messages. - GridTcpCommunicationMessageFactory.registerCommon(new GridTcpCommunicationMessageProducer() { - @Override - public GridTcpCommunicationMessageAdapter create(byte type) { - switch (type) { - case 65: - return new GridGgfsAckMessage(); - - case 66: - return new GridGgfsBlockKey(); - - case 67: - return new GridGgfsBlocksMessage(); - - case 68: - return new GridGgfsDeleteMessage(); - - case 69: - return new GridGgfsFileAffinityRange(); - - case 70: - return new GridGgfsFragmentizerRequest(); - - case 71: - return new GridGgfsFragmentizerResponse(); - - case 72: - return new GridGgfsSyncMessage(); - - default: - assert false : "Invalid GGFS message type."; - - return null; - } - } - }, 65, 66, 67, 68, 69,70, 71, 72); - // Register HDFS edition usage with license manager. GridLicenseUseRegistry.onUsage(HADOOP, getClass()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java index 6e6a974840631..752613392c9b1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java @@ -30,6 +30,8 @@ import org.jdk8.backport.*; import org.jetbrains.annotations.*; +import java.util.*; + /** * Manages offheap memory caches. */ @@ -299,6 +301,19 @@ public long entriesCount(@Nullable String spaceName) { return m == null ? -1 : m.size(); } + /** + * Gets number of elements in the given space. + * + * @param spaceName Space name. Optional. + * @param parts Partitions. + * @return Number of elements or {@code -1} if no space with the given name has been found. + */ + public long entriesCount(@Nullable String spaceName, Set parts) { + GridOffHeapPartitionedMap m = offheap(spaceName); + + return m == null ? -1 : m.size(parts); + } + /** * Gets size of a memory allocated for the entries of the given space. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java index 46227c0786fd8..320c5f2a741fe 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java @@ -64,14 +64,14 @@ public IgnitePluginProcessor(GridKernalContext ctx, IgniteConfiguration cfg) { throw new IgniteException("Provider class is null."); try { - Constructor ctr = + Constructor ctr = pluginCfg.providerClass().getConstructor(PluginContext.class); provider = ctr.newInstance(pluginCtx); } catch (NoSuchMethodException ignore) { try { - Constructor ctr = + Constructor ctr = pluginCfg.providerClass().getConstructor(pluginCfg.getClass()); provider = ctr.newInstance(pluginCfg); @@ -161,7 +161,9 @@ public T pluginContextForProvider(PluginProvider provi */ public T createComponent(Class cls) { for (PluginProvider plugin : plugins.values()) { - T comp = (T)plugin.createComponent(cls); + PluginContext ctx = pluginContextForProvider(plugin); + + T comp = (T)plugin.createComponent(ctx, cls); if (comp != null) return comp; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/GridPortableOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/GridPortableOutputStream.java index cfbf8d44154a0..4f23fd14989c1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/GridPortableOutputStream.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/GridPortableOutputStream.java @@ -158,13 +158,6 @@ public interface GridPortableOutputStream extends GridPortableStream, AutoClosea */ public void write(long addr, int cnt); - /** - * Ensure capacity. - * - * @param cnt Required byte count. - */ - public void ensureCapacity(int cnt); - /** * Close the stream releasing resources. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/GridPortableProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/GridPortableProcessor.java index 594b7679860fb..8dc3fa9263a5d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/GridPortableProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/GridPortableProcessor.java @@ -17,13 +17,13 @@ package org.apache.ignite.internal.processors.portable; +import org.apache.ignite.*; import org.apache.ignite.client.marshaller.*; +import org.apache.ignite.cluster.*; import org.apache.ignite.internal.processors.*; -import org.apache.ignite.portables.*; import org.jetbrains.annotations.*; import java.nio.*; -import java.util.*; /** * Portable processor. @@ -35,45 +35,51 @@ public interface GridPortableProcessor extends GridProcessor { */ public int typeId(String typeName); + /** + * @param obj Object to get type ID for. + * @return Type ID. + */ + public int typeId(Object obj); + /** * @param obj Object to marshal. * @param trim If {@code true} trims result byte buffer. * @return Object bytes. - * @throws org.apache.ignite.portables.PortableException In case of error. + * @throws IgniteException In case of error. */ - public ByteBuffer marshal(@Nullable Object obj, boolean trim) throws PortableException; + public ByteBuffer marshal(@Nullable Object obj, boolean trim) throws IgniteException; /** * @param arr Byte array. * @param off Offset. * @return Unmarshalled object. - * @throws org.apache.ignite.portables.PortableException In case of error. + * @throws IgniteException In case of error. */ - public Object unmarshal(byte[] arr, int off) throws PortableException; + public Object unmarshal(byte[] arr, int off) throws IgniteException; /** * @param ptr Offheap pointer. * @param forceHeap If {@code true} creates heap-based object. * @return Unmarshalled object. - * @throws org.apache.ignite.portables.PortableException In case of error. + * @throws IgniteException In case of error. */ - public Object unmarshal(long ptr, boolean forceHeap) throws PortableException; + public Object unmarshal(long ptr, boolean forceHeap) throws IgniteException; /** * Converts temporary offheap object to heap-based. * * @param obj Object. * @return Heap-based object. - * @throws org.apache.ignite.portables.PortableException In case of error. + * @throws IgniteException In case of error. */ - @Nullable public Object unwrapTemporary(@Nullable Object obj) throws PortableException; + @Nullable public Object unwrapTemporary(@Nullable Object obj) throws IgniteException; /** * @param obj Object to marshal. * @return Portable object. - * @throws org.apache.ignite.portables.PortableException In case of error. + * @throws IgniteException In case of error. */ - public Object marshalToPortable(@Nullable Object obj) throws PortableException; + public Object marshalToPortable(@Nullable Object obj) throws IgniteException; /** * @param obj Object (portable or not). @@ -94,57 +100,31 @@ public interface GridPortableProcessor extends GridProcessor { public boolean isPortable(GridClientMarshaller marsh); /** - * @return Builder. + * @param node Node to check. + * @param cacheName Cache name to check. + * @return {@code True} if portable enabled for the specified cache, {@code false} otherwise. */ - public PortableBuilder builder(int typeId); + public boolean portableEnabled(ClusterNode node, String cacheName); /** - * @return Builder. - */ - public PortableBuilder builder(String clsName); - - /** - * Creates builder initialized by existing portable object. + * Checks whether object is portable object. * - * @param portableObj Portable object to edit. - * @return Portable builder. - */ - public PortableBuilder builder(PortableObject portableObj); - - /** - * @param typeId Type ID. - * @param newMeta New meta data. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - public void addMeta(int typeId, final PortableMetadata newMeta) throws PortableException; - - /** - * @param typeId Type ID. - * @param typeName Type name. - * @param affKeyFieldName Affinity key field name. - * @param fieldTypeIds Fields map. - * @throws org.apache.ignite.portables.PortableException In case of error. + * @param obj Object to check. + * @return {@code True} if object is already a portable object, {@code false} otherwise. */ - public void updateMetaData(int typeId, String typeName, @Nullable String affKeyFieldName, - Map fieldTypeIds) throws PortableException; + public boolean isPortableObject(Object obj); /** - * @param typeId Type ID. - * @return Meta data. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - @Nullable public PortableMetadata metadata(int typeId) throws PortableException; - - /** - * @param typeIds Type ID. - * @return Meta data. - * @throws org.apache.ignite.portables.PortableException In case of error. + * Gets affinity key of portable object. + * + * @param obj Object to get affinity key for. + * @return Affinity key. */ - public Map metadata(Collection typeIds) throws PortableException; + public Object affinityKey(Object obj); /** - * @return Metadata for all types. - * @throws org.apache.ignite.portables.PortableException In case of error. + * @param obj Portable object to get field from. + * @return Field value. */ - public Collection metadata() throws PortableException; + public Object field(Object obj, String fieldName); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/os/GridOsPortableProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/os/GridOsPortableProcessor.java index 46bc955f9df23..2442eb2486ac8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/os/GridOsPortableProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/portable/os/GridOsPortableProcessor.java @@ -17,15 +17,15 @@ package org.apache.ignite.internal.processors.portable.os; +import org.apache.ignite.*; import org.apache.ignite.client.marshaller.*; +import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.*; import org.apache.ignite.internal.processors.portable.*; -import org.apache.ignite.portables.*; import org.jetbrains.annotations.*; import java.nio.*; -import java.util.*; /** * No-op implementation of {@link GridPortableProcessor}. @@ -44,27 +44,27 @@ public GridOsPortableProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public ByteBuffer marshal(@Nullable Object obj, boolean trim) throws PortableException { + @Override public ByteBuffer marshal(@Nullable Object obj, boolean trim) throws IgniteException { return null; } /** {@inheritDoc} */ - @Nullable @Override public Object unmarshal(byte[] arr, int off) throws PortableException { + @Nullable @Override public Object unmarshal(byte[] arr, int off) throws IgniteException { return null; } /** {@inheritDoc} */ - @Override public Object unmarshal(long ptr, boolean forceHeap) throws PortableException { + @Override public Object unmarshal(long ptr, boolean forceHeap) throws IgniteException { return null; } /** {@inheritDoc} */ - @Override public Object unwrapTemporary(Object obj) throws PortableException { + @Override public Object unwrapTemporary(Object obj) throws IgniteException { return null; } /** {@inheritDoc} */ - @Nullable @Override public Object marshalToPortable(@Nullable Object obj) throws PortableException { + @Nullable @Override public Object marshalToPortable(@Nullable Object obj) throws IgniteException { return obj; } @@ -84,43 +84,27 @@ public GridOsPortableProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public PortableBuilder builder(int typeId) { - return null; - } - - /** {@inheritDoc} */ - @Override public PortableBuilder builder(String clsName) { - return null; - } - - /** {@inheritDoc} */ - @Override public PortableBuilder builder(PortableObject portableObj) { - return null; + @Override public boolean portableEnabled(ClusterNode node, String cacheName) { + return false; } /** {@inheritDoc} */ - @Override public void addMeta(int typeId, PortableMetadata newMeta) throws PortableException { - // No-op. + @Override public boolean isPortableObject(Object obj) { + return false; } /** {@inheritDoc} */ - @Override public void updateMetaData(int typeId, String typeName, String affKeyFieldName, - Map fieldTypeIds) throws PortableException { - // No-op. + @Override public Object affinityKey(Object obj) { + return obj; } /** {@inheritDoc} */ - @Nullable @Override public PortableMetadata metadata(int typeId) { - return null; + @Override public int typeId(Object obj) { + return 0; } /** {@inheritDoc} */ - @Override public Map metadata(Collection typeIds) { + @Override public Object field(Object obj, String fieldName) { return null; } - - /** {@inheritDoc} */ - @Override public Collection metadata() throws PortableException { - return Collections.emptyList(); - } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 97d6523d7673d..08d0a5d7bac30 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -32,7 +32,6 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.worker.*; import org.apache.ignite.lang.*; -import org.apache.ignite.portables.*; import org.apache.ignite.spi.indexing.*; import org.jdk8.backport.*; import org.jetbrains.annotations.*; @@ -290,10 +289,8 @@ public void store(final String space, final K key, @Nullable byte[] keyBy } if (id == null) { - if (val instanceof PortableObject) { - PortableObject portable = (PortableObject)val; - - int typeId = portable.typeId(); + if (ctx.portable().isPortableObject(val)) { + int typeId = ctx.portable().typeId(val); String typeName = portableName(typeId); @@ -325,13 +322,13 @@ public void store(final String space, final K key, @Nullable byte[] keyBy d.keyClass(keyCls); d.valueClass(valCls); - if (key instanceof PortableObject) { - PortableObject portableKey = (PortableObject)key; + if (ctx.portable().isPortableObject(key)) { + int typeId = ctx.portable().typeId(key); - String typeName = portableName(portableKey.typeId()); + String typeName = portableName(typeId); if (typeName != null) { - CacheTypeMetadata keyMeta = declaredType(space, portableKey.typeId()); + CacheTypeMetadata keyMeta = declaredType(space, typeId); if (keyMeta != null) processPortableMeta(true, keyMeta, d); @@ -346,13 +343,13 @@ public void store(final String space, final K key, @Nullable byte[] keyBy processClassMeta(true, d.keyCls, keyMeta, d); } - if (val instanceof PortableObject) { - PortableObject portableVal = (PortableObject)val; + if (ctx.portable().isPortableObject(val)) { + int typeId = ctx.portable().typeId(val); - String typeName = portableName(portableVal.typeId()); + String typeName = portableName(typeId); if (typeName != null) { - CacheTypeMetadata valMeta = declaredType(space, portableVal.typeId()); + CacheTypeMetadata valMeta = declaredType(space, typeId); d.name(typeName); @@ -922,7 +919,7 @@ static void processClassMeta(boolean key, Class cls, CacheTypeMetadata meta, * @param d Type descriptor. * @throws IgniteCheckedException If failed. */ - static void processPortableMeta(boolean key, CacheTypeMetadata meta, TypeDescriptor d) + private void processPortableMeta(boolean key, CacheTypeMetadata meta, TypeDescriptor d) throws IgniteCheckedException { for (Map.Entry> entry : meta.getAscendingFields().entrySet()) { PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue()); @@ -996,7 +993,7 @@ static void processPortableMeta(boolean key, CacheTypeMetadata meta, TypeDescrip * @param resType Result type. * @return Portable property. */ - static PortableProperty buildPortableProperty(String pathStr, Class resType) { + private PortableProperty buildPortableProperty(String pathStr, Class resType) { String[] path = pathStr.split("\\."); PortableProperty res = null; @@ -1240,7 +1237,7 @@ public boolean knowsClass(Class cls) { /** * */ - private static class PortableProperty extends Property { + private class PortableProperty extends Property { /** Property name. */ private String propName; @@ -1271,11 +1268,11 @@ private PortableProperty(String propName, PortableProperty parent, Class type if (obj == null) return null; - if (!(obj instanceof PortableObject)) + if (!ctx.portable().isPortableObject(obj)) throw new IgniteCheckedException("Non-portable object received as a result of property extraction " + "[parent=" + parent + ", propName=" + propName + ", obj=" + obj + ']'); - return ((PortableObject)obj).field(propName); + return ctx.portable().field(obj, propName); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java index 365a970335094..3a529f547d6ff 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java @@ -28,7 +28,6 @@ import org.apache.ignite.internal.processors.rest.handlers.cache.*; import org.apache.ignite.internal.processors.rest.handlers.datastructures.*; import org.apache.ignite.internal.processors.rest.handlers.log.*; -import org.apache.ignite.internal.processors.rest.handlers.metadata.*; import org.apache.ignite.internal.processors.rest.handlers.task.*; import org.apache.ignite.internal.processors.rest.handlers.top.*; import org.apache.ignite.internal.processors.rest.handlers.version.*; @@ -255,7 +254,6 @@ public GridRestProcessor(GridKernalContext ctx) { addHandler(new GridTopologyCommandHandler(ctx)); addHandler(new GridVersionCommandHandler(ctx)); addHandler(new GridLogCommandHandler(ctx)); - addHandler(new GridPortableMetadataHandler(ctx)); addHandler(new DataStructuresCommandHandler(ctx)); // Start protocols. @@ -331,8 +329,8 @@ public GridRestProcessor(GridKernalContext ctx) { } /** - * Applies {@link org.apache.ignite.configuration.ClientMessageInterceptor} - * from {@link org.apache.ignite.configuration.ClientConnectionConfiguration#getClientMessageInterceptor()} + * Applies {@link ClientMessageInterceptor} + * from {@link ClientConnectionConfiguration#getClientMessageInterceptor()} * to all user parameters in the request. * * @param req Client request. @@ -378,8 +376,8 @@ else if (req instanceof GridRestTaskRequest) { } /** - * Applies {@link org.apache.ignite.configuration.ClientMessageInterceptor} from - * {@link org.apache.ignite.configuration.ClientConnectionConfiguration#getClientMessageInterceptor()} + * Applies {@link ClientMessageInterceptor} from + * {@link ClientConnectionConfiguration#getClientMessageInterceptor()} * to all user objects in the response. * * @param res Response. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAbstractMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAbstractMessage.java index 9f49377a2adfc..c6557bc7971e0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAbstractMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAbstractMessage.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.rest.client.message; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.io.*; import java.util.*; @@ -26,7 +25,7 @@ /** * This class provides implementation for commit message fields and cannot be used directly. */ -public abstract class GridClientAbstractMessage implements GridClientMessage, Externalizable, PortableMarshalAware { +public abstract class GridClientAbstractMessage implements GridClientMessage, Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -96,20 +95,6 @@ public abstract class GridClientAbstractMessage implements GridClientMessage, Ex sesTok = U.readByteArray(in); } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - PortableRawWriter raw = writer.rawWriter(); - - raw.writeByteArray(sesTok); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - PortableRawReader raw = reader.rawReader(); - - sesTok = raw.readByteArray(); - } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridClientAbstractMessage.class, this, super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAuthenticationRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAuthenticationRequest.java index c9f28fc09ec79..8eed15756f7b8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAuthenticationRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAuthenticationRequest.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.rest.client.message; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.io.*; @@ -60,24 +59,6 @@ public void credentials(Object cred) { cred = in.readObject(); } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriter raw = writer.rawWriter(); - - raw.writeObject(cred); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReader raw = reader.rawReader(); - - cred = raw.readObject(); - } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridClientAuthenticationRequest.class, this, super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheQueryRequest.java index f689b691d3410..b62d2b535a37c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheQueryRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheQueryRequest.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.rest.client.message; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import org.jetbrains.annotations.*; import java.io.*; @@ -320,50 +319,6 @@ public void queryArguments(Object[] qryArgs) { this.qryArgs = qryArgs; } - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReader rawReader = reader.rawReader(); - - qryId = rawReader.readLong(); - op = GridQueryOperation.fromOrdinal(rawReader.readInt()); - type = GridQueryType.fromOrdinal(rawReader.readInt()); - cacheName = rawReader.readString(); - clause = rawReader.readString(); - pageSize = rawReader.readInt(); - timeout = rawReader.readLong(); - includeBackups = rawReader.readBoolean(); - enableDedup = rawReader.readBoolean(); - keepPortable = rawReader.readBoolean(); - clsName = rawReader.readString(); - rmtReducerClsName = rawReader.readString(); - rmtTransformerClsName = rawReader.readString(); - qryArgs = rawReader.readObjectArray(); - } - - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriter rawWriter = writer.rawWriter(); - - rawWriter.writeLong(qryId); - rawWriter.writeInt(op.ordinal()); - rawWriter.writeInt(type == null ? -1 : type.ordinal()); - rawWriter.writeString(cacheName); - rawWriter.writeString(clause); - rawWriter.writeInt(pageSize); - rawWriter.writeLong(timeout); - rawWriter.writeBoolean(includeBackups); - rawWriter.writeBoolean(enableDedup); - rawWriter.writeBoolean(keepPortable); - rawWriter.writeString(clsName); - rawWriter.writeString(rmtReducerClsName); - rawWriter.writeString(rmtTransformerClsName); - rawWriter.writeObjectArray(qryArgs); - } - /** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheRequest.java index 0bfe08a11ca14..58e973b399113 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheRequest.java @@ -17,9 +17,7 @@ package org.apache.ignite.internal.processors.rest.client.message; -import org.apache.ignite.internal.util.portable.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import org.jetbrains.annotations.*; import java.io.*; @@ -229,52 +227,6 @@ public int cacheFlagsOn() { return cacheFlagsOn; } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriterEx raw = (PortableRawWriterEx)writer.rawWriter(); - - raw.writeInt(op.ordinal()); - raw.writeString(cacheName); - raw.writeInt(cacheFlagsOn); - raw.writeObjectDetached(key); - raw.writeObjectDetached(val); - raw.writeObjectDetached(val2); - - raw.writeInt(vals != null ? vals.size() : -1); - - if (vals != null) { - for (Map.Entry e : vals.entrySet()) { - raw.writeObjectDetached(e.getKey()); - raw.writeObjectDetached(e.getValue()); - } - } - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReaderEx raw = (PortableRawReaderEx)reader.rawReader(); - - op = GridCacheOperation.fromOrdinal(raw.readInt()); - cacheName = raw.readString(); - cacheFlagsOn = raw.readInt(); - key = raw.readObjectDetached(); - val = raw.readObjectDetached(); - val2 = raw.readObjectDetached(); - - int valsSize = raw.readInt(); - - if (valsSize >= 0) { - vals = U.newHashMap(valsSize); - - for (int i = 0; i < valsSize; i++) - vals.put(raw.readObjectDetached(), raw.readObjectDetached()); - } - } - /** {@inheritDoc} */ @SuppressWarnings("deprecation") @Override public void writeExternal(ObjectOutput out) throws IOException { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientGetMetaDataRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientGetMetaDataRequest.java deleted file mode 100644 index b4ee5dc3e9149..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientGetMetaDataRequest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.client.message; - -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; - -import java.util.*; - -/** - * Metadata request. - */ -public class GridClientGetMetaDataRequest extends GridClientAbstractMessage { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private Collection typeIds; - - /** - * @return Type IDs. - */ - public Collection typeIds() { - return typeIds; - } - - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriter raw = writer.rawWriter(); - - raw.writeCollection(typeIds); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReader raw = reader.rawReader(); - - typeIds = raw.readCollection(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridClientGetMetaDataRequest.class, this); - } -} 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 deleted file mode 100644 index 386b6eb353334..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeRequestWrapper.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.client.message; - -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.nio.*; - -/** - * Client handshake wrapper for direct marshalling. - */ -public class GridClientHandshakeRequestWrapper extends GridTcpCommunicationMessageAdapter { - /** */ - private static final long serialVersionUID = -5705048094821942662L; - - /** Signal char. */ - public static final byte HANDSHAKE_HEADER = (byte)0x91; - - /** Handshake bytes. */ - private byte[] bytes; - - /** - * - */ - public GridClientHandshakeRequestWrapper() { - // No-op. - } - - /** - * - * @param req Handshake request. - */ - public GridClientHandshakeRequestWrapper(GridClientHandshakeRequest req) { - bytes = req.rawBytes(); - } - - /** - * @return Handshake bytes. - */ - public byte[] bytes() { - return bytes; - } - - /** {@inheritDoc} */ - @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!commState.typeWritten) { - if (!commState.putByte(directType())) - return false; - - commState.typeWritten = true; - } - - switch (commState.idx) { - case 0: - if (!commState.putByteArrayClient(bytes)) - return false; - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); - - switch (commState.idx) { - case 0: - byte[] bytes0 = commState.getByteArrayClient(GridClientHandshakeRequest.PACKET_SIZE); - - if (bytes0 == BYTE_ARR_NOT_READ) - return false; - - bytes = bytes0; - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return HANDSHAKE_HEADER; - } - - /** {@inheritDoc} */ - @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { - GridClientHandshakeRequestWrapper _clone = new GridClientHandshakeRequestWrapper(); - - clone0(_clone); - - return _clone; - } - - /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - GridClientHandshakeRequestWrapper _clone = (GridClientHandshakeRequestWrapper)_msg; - - _clone.bytes = bytes; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridClientHandshakeRequestWrapper.class, this); - } -} 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 deleted file mode 100644 index 1e20a9c1a3737..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeResponseWrapper.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.client.message; - -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.nio.*; - -/** - * Client handshake wrapper for direct marshalling. - */ -public class GridClientHandshakeResponseWrapper extends GridTcpCommunicationMessageAdapter { - /** */ - private static final long serialVersionUID = -1529807975073967381L; - - /** */ - private byte code; - - /** - * - */ - public GridClientHandshakeResponseWrapper() { - // No-op. - } - - /** - * @param code Response code. - */ - public GridClientHandshakeResponseWrapper(byte code) { - this.code = code; - } - - /** {@inheritDoc} */ - @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!commState.typeWritten) { - if (!commState.putByte(directType())) - return false; - - commState.typeWritten = true; - } - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); - - return true; - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return code; - } - - /** {@inheritDoc} */ - @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { - GridClientHandshakeResponseWrapper _clone = new GridClientHandshakeResponseWrapper(); - - clone0(_clone); - - return _clone; - } - - /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - GridClientHandshakeResponseWrapper _clone = (GridClientHandshakeResponseWrapper)_msg; - - _clone.code = code; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridClientHandshakeResponseWrapper.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientLogRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientLogRequest.java index 2bd8735e1d6b2..af931c8bbcb74 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientLogRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientLogRequest.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.rest.client.message; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.io.*; @@ -80,28 +79,6 @@ public void to(int to) { this.to = to; } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriter raw = writer.rawWriter(); - - raw.writeString(path); - raw.writeInt(from); - raw.writeInt(to); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReader raw = reader.rawReader(); - - path = raw.readString(); - from = raw.readInt(); - to = raw.readInt(); - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); 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 deleted file mode 100644 index 6ff66ce43283b..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMessageWrapper.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.client.message; - -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.nio.*; -import java.util.*; - -/** - * Client message wrapper for direct marshalling. - */ -public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter { - /** */ - private static final long serialVersionUID = 5284375300887454697L; - - /** Client request header. */ - public static final byte REQ_HEADER = (byte)0x90; - - /** */ - private int msgSize; - - /** */ - private long reqId; - - /** */ - private UUID clientId; - - /** */ - private UUID destId; - - /** */ - private ByteBuffer msg; - - /** - * @return Request ID. - */ - public long requestId() { - return reqId; - } - - /** - * @param reqId Request ID. - */ - public void requestId(long reqId) { - this.reqId = reqId; - } - - /** - * @return Message size. - */ - public int messageSize() { - return msgSize; - } - - /** - * @param msgSize Message size. - */ - public void messageSize(int msgSize) { - this.msgSize = msgSize; - } - - /** - * @return Client ID. - */ - public UUID clientId() { - return clientId; - } - - /** - * @param clientId Client ID. - */ - public void clientId(UUID clientId) { - this.clientId = clientId; - } - - /** - * @return Destination ID. - */ - public UUID destinationId() { - return destId; - } - - /** - * @param destId Destination ID. - */ - public void destinationId(UUID destId) { - this.destId = destId; - } - - /** - * @return Message buffer. - */ - public ByteBuffer message() { - return msg; - } - - /** - * @return Message bytes. - */ - public byte[] messageArray() { - assert msg.hasArray(); - assert msg.position() == 0 && msg.remaining() == msg.capacity(); - - return msg.array(); - } - - /** - * @param msg Message bytes. - */ - public void message(ByteBuffer msg) { - this.msg = msg; - } - - /** {@inheritDoc} */ - @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!commState.typeWritten) { - if (!commState.putByte(directType())) - return false; - - commState.typeWritten = true; - } - - switch (commState.idx) { - case 0: - if (!commState.putIntClient(msgSize)) - return false; - - commState.idx++; - - case 1: - if (!commState.putLongClient(reqId)) - return false; - - commState.idx++; - - case 2: - if (!commState.putUuidClient(clientId)) - return false; - - commState.idx++; - - case 3: - if (!commState.putUuidClient(destId)) - return false; - - commState.idx++; - - case 4: - if (!commState.putByteBufferClient(msg)) - return false; - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); - - switch (commState.idx) { - case 0: - if (buf.remaining() < 4) - return false; - - msgSize = commState.getIntClient(); - - if (msgSize == 0) // Ping message. - return true; - - commState.idx++; - - case 1: - if (buf.remaining() < 8) - return false; - - reqId = commState.getLongClient(); - - commState.idx++; - - case 2: - UUID clientId0 = commState.getUuidClient(); - - if (clientId0 == UUID_NOT_READ) - return false; - - clientId = clientId0; - - commState.idx++; - - case 3: - UUID destId0 = commState.getUuidClient(); - - if (destId0 == UUID_NOT_READ) - return false; - - destId = destId0; - - commState.idx++; - - case 4: - byte[] msg0 = commState.getByteArrayClient(msgSize - 40); - - if (msg0 == BYTE_ARR_NOT_READ) - return false; - - msg = ByteBuffer.wrap(msg0); - - commState.idx++; - } - - return true; - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return REQ_HEADER; - } - - /** {@inheritDoc} */ - @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { - GridClientMessageWrapper _clone = new GridClientMessageWrapper(); - - clone0(_clone); - - return _clone; - } - - /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - GridClientMessageWrapper _clone = (GridClientMessageWrapper)_msg; - - _clone.reqId = reqId; - _clone.msgSize = msgSize; - _clone.clientId = clientId; - _clone.destId = destId; - _clone.msg = msg; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridClientMessageWrapper.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMetaDataResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMetaDataResponse.java deleted file mode 100644 index b74d922997c37..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMetaDataResponse.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.client.message; - -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; - -import java.util.*; - -/** - * Metadata response. - */ -public class GridClientMetaDataResponse implements PortableMarshalAware { - /** */ - private Map meta; - - /** - * @param meta Portable objects metadata. - */ - public void metaData(Map meta) { - this.meta = meta; - } - - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - PortableRawWriter raw = writer.rawWriter(); - - raw.writeMap(meta); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - PortableRawReader raw = reader.rawReader(); - - meta = raw.readMap(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridClientMetaDataResponse.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java index bedbb97df4a12..6605a151fc29d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.rest.client.message; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.io.*; import java.util.*; @@ -26,7 +25,7 @@ /** * Node bean. */ -public class GridClientNodeBean implements Externalizable, PortableMarshalAware { +public class GridClientNodeBean implements Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -254,43 +253,6 @@ public void setTcpPort(int tcpPort) { return nodeId == null ? other.nodeId == null : nodeId.equals(other.nodeId); } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - PortableRawWriter raw = writer.rawWriter(); - - raw.writeInt(tcpPort); - raw.writeInt(replicaCnt); - raw.writeString(dfltCacheMode); - raw.writeMap(attrs); - raw.writeMap(caches); - raw.writeCollection(tcpAddrs); - raw.writeCollection(tcpHostNames); - raw.writeUuid(nodeId); - raw.writeObject(consistentId); - raw.writeObject(metrics); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - PortableRawReader raw = reader.rawReader(); - - tcpPort = raw.readInt(); - replicaCnt = raw.readInt(); - - dfltCacheMode = raw.readString(); - - attrs = raw.readMap(); - caches = raw.readMap(); - - tcpAddrs = raw.readCollection(); - tcpHostNames = raw.readCollection(); - - nodeId = raw.readUuid(); - - consistentId = raw.readObject(); - metrics = (GridClientNodeMetricsBean)raw.readObject(); - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(tcpPort); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeMetricsBean.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeMetricsBean.java index 98a499a47d5ab..91bfd6a13de49 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeMetricsBean.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeMetricsBean.java @@ -17,14 +17,12 @@ package org.apache.ignite.internal.processors.rest.client.message; -import org.apache.ignite.portables.*; - import java.io.*; /** * Node metrics bean. */ -public class GridClientNodeMetricsBean implements Externalizable, PortableMarshalAware { +public class GridClientNodeMetricsBean implements Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -1348,122 +1346,6 @@ public boolean equals(Object obj) { toString(); } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - PortableRawWriter raw = writer.rawWriter(); - - raw.writeLong(lastUpdateTime); - raw.writeInt(maxActiveJobs); - raw.writeInt(curActiveJobs); - raw.writeFloat(avgActiveJobs); - raw.writeInt(maxWaitingJobs); - raw.writeInt(curWaitingJobs); - raw.writeFloat(avgWaitingJobs); - raw.writeInt(maxRejectedJobs); - raw.writeInt(curRejectedJobs); - raw.writeFloat(avgRejectedJobs); - raw.writeInt(maxCancelledJobs); - raw.writeInt(curCancelledJobs); - raw.writeFloat(avgCancelledJobs); - raw.writeInt(totalRejectedJobs); - raw.writeInt(totalCancelledJobs); - raw.writeInt(totalExecutedJobs); - raw.writeLong(maxJobWaitTime); - raw.writeLong(curJobWaitTime); - raw.writeDouble(avgJobWaitTime); - raw.writeLong(maxJobExecTime); - raw.writeLong(curJobExecTime); - raw.writeDouble(avgJobExecTime); - raw.writeInt(totalExecTasks); - raw.writeLong(totalIdleTime); - raw.writeLong(curIdleTime); - raw.writeInt(availProcs); - raw.writeDouble(load); - raw.writeDouble(avgLoad); - raw.writeDouble(gcLoad); - raw.writeLong(heapInit); - raw.writeLong(heapUsed); - raw.writeLong(heapCommitted); - raw.writeLong(heapMax); - raw.writeLong(nonHeapInit); - raw.writeLong(nonHeapUsed); - raw.writeLong(nonHeapCommitted); - raw.writeLong(nonHeapMax); - raw.writeLong(upTime); - raw.writeLong(startTime); - raw.writeLong(nodeStartTime); - raw.writeInt(threadCnt); - raw.writeInt(peakThreadCnt); - raw.writeLong(startedThreadCnt); - raw.writeInt(daemonThreadCnt); - raw.writeLong(fileSysFreeSpace); - raw.writeLong(fileSysTotalSpace); - raw.writeLong(fileSysUsableSpace); - raw.writeLong(lastDataVer); - raw.writeInt(sentMsgsCnt); - raw.writeLong(sentBytesCnt); - raw.writeInt(rcvdMsgsCnt); - raw.writeLong(rcvdBytesCnt); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - PortableRawReader raw = reader.rawReader(); - - lastUpdateTime = raw.readLong(); - maxActiveJobs = raw.readInt(); - curActiveJobs = raw.readInt(); - avgActiveJobs = raw.readFloat(); - maxWaitingJobs = raw.readInt(); - curWaitingJobs = raw.readInt(); - avgWaitingJobs = raw.readFloat(); - maxRejectedJobs = raw.readInt(); - curRejectedJobs = raw.readInt(); - avgRejectedJobs = raw.readFloat(); - maxCancelledJobs = raw.readInt(); - curCancelledJobs = raw.readInt(); - avgCancelledJobs = raw.readFloat(); - totalRejectedJobs = raw.readInt(); - totalCancelledJobs = raw.readInt(); - totalExecutedJobs = raw.readInt(); - maxJobWaitTime = raw.readLong(); - curJobWaitTime = raw.readLong(); - avgJobWaitTime = raw.readDouble(); - maxJobExecTime = raw.readLong(); - curJobExecTime = raw.readLong(); - avgJobExecTime = raw.readDouble(); - totalExecTasks = raw.readInt(); - totalIdleTime = raw.readLong(); - curIdleTime = raw.readLong(); - availProcs = raw.readInt(); - load = raw.readDouble(); - avgLoad = raw.readDouble(); - gcLoad = raw.readDouble(); - heapInit = raw.readLong(); - heapUsed = raw.readLong(); - heapCommitted = raw.readLong(); - heapMax = raw.readLong(); - nonHeapInit = raw.readLong(); - nonHeapUsed = raw.readLong(); - nonHeapCommitted = raw.readLong(); - nonHeapMax = raw.readLong(); - upTime = raw.readLong(); - startTime = raw.readLong(); - nodeStartTime = raw.readLong(); - threadCnt = raw.readInt(); - peakThreadCnt = raw.readInt(); - startedThreadCnt = raw.readLong(); - daemonThreadCnt = raw.readInt(); - fileSysFreeSpace = raw.readLong(); - fileSysTotalSpace = raw.readLong(); - fileSysUsableSpace = raw.readLong(); - lastDataVer = raw.readLong(); - sentMsgsCnt = raw.readInt(); - sentBytesCnt = raw.readLong(); - rcvdMsgsCnt = raw.readInt(); - rcvdBytesCnt = raw.readLong(); - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeLong(lastUpdateTime); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacket.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacket.java index fef8a8d1a8e93..90235dff37e7d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacket.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacket.java @@ -17,6 +17,8 @@ package org.apache.ignite.internal.processors.rest.client.message; +import static org.apache.ignite.internal.processors.rest.protocols.tcp.GridMemcachedMessage.*; + /** * Fictive ping packet. */ @@ -28,7 +30,7 @@ public class GridClientPingPacket extends GridClientAbstractMessage { public static final GridClientMessage PING_MESSAGE = new GridClientPingPacket(); /** Ping packet. */ - public static final byte[] PING_PACKET = new byte[] {(byte)0x90, 0x00, 0x00, 0x00, 0x00}; + public static final byte[] PING_PACKET = new byte[] {IGNITE_REQ_FLAG, 0x00, 0x00, 0x00, 0x00}; /** {@inheritDoc} */ @Override public String toString() { 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 deleted file mode 100644 index 6fd95b5356ecf..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacketWrapper.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.client.message; - -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.nio.*; - -/** - * Ping packet wrapper for direct marshalling. - */ -public class GridClientPingPacketWrapper extends GridTcpCommunicationMessageAdapter { - /** */ - private static final long serialVersionUID = -3956036611004055629L; - - /** Ping message size (always zero). */ - private int size; - - /** {@inheritDoc} */ - @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!commState.typeWritten) { - if (!commState.putByte(directType())) - return false; - - commState.typeWritten = true; - } - - switch (commState.idx) { - case 0: - if (!commState.putIntClient(size)) - return false; - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean readFrom(ByteBuffer buf) { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return GridClientMessageWrapper.REQ_HEADER; - } - - /** {@inheritDoc} */ - @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { - GridClientPingPacketWrapper _clone = new GridClientPingPacketWrapper(); - - clone0(_clone); - - return _clone; - } - - /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - GridClientPingPacketWrapper _clone = (GridClientPingPacketWrapper)_msg; - - _clone.size = size; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridClientPingPacketWrapper.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPortableMetaData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPortableMetaData.java index 5b9a2f6844367..e96baf5e11ce5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPortableMetaData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPortableMetaData.java @@ -18,14 +18,13 @@ package org.apache.ignite.internal.processors.rest.client.message; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.util.*; /** * Portable meta data sent from client. */ -public class GridClientPortableMetaData implements PortableMarshalAware { +public class GridClientPortableMetaData { /** */ private int typeId; @@ -66,26 +65,6 @@ public String affinityKeyFieldName() { return affKeyFieldName; } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - PortableRawWriter raw = writer.rawWriter(); - - raw.writeInt(typeId); - raw.writeString(typeName); - raw.writeString(affKeyFieldName); - raw.writeMap(fields); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - PortableRawReader raw = reader.rawReader(); - - typeId = raw.readInt(); - typeName = raw.readString(); - affKeyFieldName = raw.readString(); - fields = raw.readMap(); - } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridClientPortableMetaData.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPutMetaDataRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPutMetaDataRequest.java deleted file mode 100644 index 487da7ad6acd5..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPutMetaDataRequest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.client.message; - -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; - -import java.util.*; - -/** - * Metadata put request. - */ -public class GridClientPutMetaDataRequest extends GridClientAbstractMessage { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private Collection meta; - - /** - * @return Type IDs. - */ - public Collection metaData() { - return meta; - } - - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriter raw = writer.rawWriter(); - - raw.writeCollection(meta); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReader raw = reader.rawReader(); - - meta = raw.readCollection(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridClientPutMetaDataRequest.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientResponse.java index 09e542f237be4..c9a7263baadcf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientResponse.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.rest.client.message; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.io.*; @@ -92,28 +91,6 @@ public void result(Object res) { this.res = res; } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriter raw = writer.rawWriter(); - - raw.writeInt(successStatus); - raw.writeString(errorMsg); - raw.writeObject(res); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReader raw = reader.rawReader(); - - successStatus = raw.readInt(); - errorMsg = raw.readString(); - res = raw.readObject(); - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java index 8a43030dfab16..a7fa86e914693 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java @@ -17,9 +17,7 @@ package org.apache.ignite.internal.processors.rest.client.message; -import org.apache.ignite.internal.util.portable.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.io.*; @@ -101,32 +99,6 @@ public void keepPortables(boolean keepPortables) { 31 * (arg == null ? 0 : arg.hashCode()); } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriterEx raw = (PortableRawWriterEx)writer.rawWriter(); - - raw.writeString(taskName); - raw.writeBoolean(keepPortables); - - if (keepPortables) - raw.writeObjectDetached(arg); - else - raw.writeObject(arg); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReaderEx raw = (PortableRawReaderEx)reader.rawReader(); - - taskName = raw.readString(); - keepPortables = raw.readBoolean(); - arg = keepPortables ? raw.readObjectDetached() : raw.readObject(); - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskResultBean.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskResultBean.java index 12f4fdf1f7430..696ac034d7cfc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskResultBean.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskResultBean.java @@ -17,16 +17,14 @@ package org.apache.ignite.internal.processors.rest.client.message; -import org.apache.ignite.internal.util.portable.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.io.*; /** * Task result. */ -public class GridClientTaskResultBean implements Externalizable, PortableMarshalAware { +public class GridClientTaskResultBean implements Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -99,30 +97,6 @@ public void setError(String error) { this.error = error; } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - PortableRawWriterEx raw = (PortableRawWriterEx)writer.rawWriter(); - - raw.writeString(id); - raw.writeBoolean(finished); - - raw.writeObject(res); - - raw.writeString(error); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - PortableRawReaderEx raw = (PortableRawReaderEx)reader.rawReader(); - - id = raw.readString(); - finished = raw.readBoolean(); - - res = raw.readObject(); - - error = raw.readString(); - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeString(out, id); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTopologyRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTopologyRequest.java index 5a817c2bd7300..8b27084b62ac5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTopologyRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTopologyRequest.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.rest.client.message; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import java.io.*; import java.util.*; @@ -118,30 +117,6 @@ public void nodeIp(String nodeIp) { (includeAttrs ? 1 : 0); } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - super.writePortable(writer); - - PortableRawWriter raw = writer.rawWriter(); - - raw.writeUuid(nodeId); - raw.writeString(nodeIp); - raw.writeBoolean(includeMetrics); - raw.writeBoolean(includeAttrs); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - super.readPortable(reader); - - PortableRawReader raw = reader.rawReader(); - - nodeId = raw.readUuid(); - nodeIp = raw.readString(); - includeMetrics = raw.readBoolean(); - includeAttrs = raw.readBoolean(); - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridRouterRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridRouterRequest.java index 34efcf6adf184..6dcbf923befe1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridRouterRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridRouterRequest.java @@ -37,6 +37,7 @@ public class GridRouterRequest extends GridClientAbstractMessage { */ public GridRouterRequest(byte[] body, Long reqId, UUID clientId, UUID destId) { this.body = body; + destinationId(destId); clientId(clientId); requestId(reqId); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridRouterResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridRouterResponse.java index ce5104cafe309..2ff3e21a1900d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridRouterResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridRouterResponse.java @@ -74,7 +74,7 @@ public int status() { /** {@inheritDoc} */ @Override public String toString() { - return "GridRoutedResponse [" + + return "GridRouterResponse [" + "clientId=" + clientId() + ", reqId=" + requestId() + ", destId=" + destinationId() + diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheClientQueryResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheClientQueryResult.java index cd16cb862a35c..b994caeb4f413 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheClientQueryResult.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheClientQueryResult.java @@ -17,15 +17,13 @@ package org.apache.ignite.internal.processors.rest.handlers.cache; -import org.apache.ignite.portables.*; - import java.io.*; import java.util.*; /** * Client query result. */ -public class GridCacheClientQueryResult implements PortableMarshalAware, Serializable { +public class GridCacheClientQueryResult implements Serializable { /** */ private static final long serialVersionUID = 0L; @@ -96,24 +94,4 @@ public UUID nodeId() { public void nodeId(UUID nodeId) { this.nodeId = nodeId; } - - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - PortableRawWriter rawWriter = writer.rawWriter(); - - rawWriter.writeBoolean(last); - rawWriter.writeLong(qryId); - rawWriter.writeUuid(nodeId); - rawWriter.writeCollection(items); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - PortableRawReader rawReader = reader.rawReader(); - - last = rawReader.readBoolean(); - qryId = rawReader.readLong(); - nodeId = rawReader.readUuid(); - items = rawReader.readCollection(); - } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/metadata/GridPortableMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/metadata/GridPortableMetadataHandler.java deleted file mode 100644 index 1c53a9d945d46..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/metadata/GridPortableMetadataHandler.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.handlers.metadata; - -import org.apache.ignite.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.internal.processors.rest.*; -import org.apache.ignite.internal.processors.rest.client.message.*; -import org.apache.ignite.internal.processors.rest.handlers.*; -import org.apache.ignite.internal.processors.rest.request.*; -import org.apache.ignite.internal.util.future.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; - -import java.util.*; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.*; - -/** - * Portable metadata handler. - */ -public class GridPortableMetadataHandler extends GridRestCommandHandlerAdapter { - /** Supported commands. */ - private static final Collection SUPPORTED_COMMANDS = U.sealList( - PUT_PORTABLE_METADATA, - GET_PORTABLE_METADATA - ); - - /** - * @param ctx Context. - */ - public GridPortableMetadataHandler(GridKernalContext ctx) { - super(ctx); - } - - /** {@inheritDoc} */ - @Override public Collection supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public IgniteInternalFuture handleAsync(GridRestRequest req) { - assert SUPPORTED_COMMANDS.contains(req.command()) : req.command(); - - try { - if (req.command() == GET_PORTABLE_METADATA) { - GridRestPortableGetMetaDataRequest metaReq = (GridRestPortableGetMetaDataRequest)req; - - GridRestResponse res = new GridRestResponse(); - - Map meta = ctx.portable().metadata(metaReq.typeIds()); - - GridClientMetaDataResponse metaRes = new GridClientMetaDataResponse(); - - metaRes.metaData(meta); - - res.setResponse(metaRes); - - return new GridFinishedFuture<>(ctx, res); - } - else { - assert req.command() == PUT_PORTABLE_METADATA; - - GridRestPortablePutMetaDataRequest metaReq = (GridRestPortablePutMetaDataRequest)req; - - for (GridClientPortableMetaData meta : metaReq.metaData()) - ctx.portable().updateMetaData(meta.typeId(), - meta.typeName(), - meta.affinityKeyFieldName(), - meta.fields()); - - GridRestResponse res = new GridRestResponse(); - - res.setResponse(true); - - return new GridFinishedFuture<>(ctx, res); - } - } - catch (IgniteException e) { - return new GridFinishedFuture<>(ctx, e); - } - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridPortableMetadataHandler.class, this, super.toString()); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskCommandHandler.java index a3e2311a46037..f9004c305e51e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskCommandHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskCommandHandler.java @@ -34,7 +34,6 @@ import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; -import org.apache.ignite.portables.*; import org.apache.ignite.resources.*; import org.jetbrains.annotations.*; @@ -263,7 +262,7 @@ private IgniteInternalFuture handleAsyncUnsafe(final GridRestR res.setResponse(taskRestRes); fut.onDone(res); } - catch (PortableException e) { + catch (IgniteException e) { fut.onDone(new IgniteCheckedException("Failed to marshal task result: " + desc.result(), e)); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskResultRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskResultRequest.java index d6e8459e565ed..637fa805e8638 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskResultRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskResultRequest.java @@ -18,8 +18,8 @@ package org.apache.ignite.internal.processors.rest.handlers.task; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -27,7 +27,7 @@ /** * Task result request. */ -public class GridTaskResultRequest extends GridTcpCommunicationMessageAdapter { +public class GridTaskResultRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -100,7 +100,7 @@ public void topic(String topic) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridTaskResultRequest _clone = new GridTaskResultRequest(); clone0(_clone); @@ -109,7 +109,7 @@ public void topic(String topic) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridTaskResultRequest _clone = (GridTaskResultRequest)_msg; _clone.taskId = taskId; @@ -120,27 +120,27 @@ public void topic(String topic) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(taskId)) + if (!writer.writeIgniteUuid("taskId", taskId)) return false; - commState.idx++; + state++; case 1: - if (!commState.putByteArray(topicBytes)) + if (!writer.writeByteArray("topicBytes", topicBytes)) return false; - commState.idx++; + state++; } @@ -150,28 +150,24 @@ public void topic(String topic) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid taskId0 = commState.getGridUuid(); + taskId = reader.readIgniteUuid("taskId"); - if (taskId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - taskId = taskId0; - - commState.idx++; + state++; case 1: - byte[] topicBytes0 = commState.getByteArray(); + topicBytes = reader.readByteArray("topicBytes"); - if (topicBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - topicBytes = topicBytes0; - - commState.idx++; + state++; } @@ -180,6 +176,6 @@ public void topic(String topic) { /** {@inheritDoc} */ @Override public byte directType() { - return 73; + return 76; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskResultResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskResultResponse.java index fb20156452eff..384cfb3c7e082 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskResultResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/task/GridTaskResultResponse.java @@ -18,7 +18,7 @@ package org.apache.ignite.internal.processors.rest.handlers.task; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.nio.*; @@ -26,7 +26,7 @@ /** * Task result response. */ -public class GridTaskResultResponse extends GridTcpCommunicationMessageAdapter { +public class GridTaskResultResponse extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -118,7 +118,7 @@ public void error(String err) { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridTaskResultResponse _clone = new GridTaskResultResponse(); clone0(_clone); @@ -127,7 +127,7 @@ public void error(String err) { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridTaskResultResponse _clone = (GridTaskResultResponse)_msg; _clone.res = res; @@ -140,39 +140,39 @@ public void error(String err) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putString(err)) + if (!writer.writeString("err", err)) return false; - commState.idx++; + state++; case 1: - if (!commState.putBoolean(finished)) + if (!writer.writeBoolean("finished", finished)) return false; - commState.idx++; + state++; case 2: - if (!commState.putBoolean(found)) + if (!writer.writeBoolean("found", found)) return false; - commState.idx++; + state++; case 3: - if (!commState.putByteArray(resBytes)) + if (!writer.writeByteArray("resBytes", resBytes)) return false; - commState.idx++; + state++; } @@ -182,44 +182,40 @@ public void error(String err) { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - String err0 = commState.getString(); + err = reader.readString("err"); - if (err0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - err = err0; - - commState.idx++; + state++; case 1: - if (buf.remaining() < 1) - return false; + finished = reader.readBoolean("finished"); - finished = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - if (buf.remaining() < 1) - return false; + found = reader.readBoolean("found"); - found = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - byte[] resBytes0 = commState.getByteArray(); + resBytes = reader.readByteArray("resBytes"); - if (resBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - resBytes = resBytes0; - - commState.idx++; + state++; } @@ -228,6 +224,6 @@ public void error(String err) { /** {@inheritDoc} */ @Override public byte directType() { - return 74; + return 77; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridClientPacketType.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridClientPacketType.java index 0bc8099cb9548..e47e825a20182 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridClientPacketType.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridClientPacketType.java @@ -27,6 +27,9 @@ public enum GridClientPacketType { /** Ignite handshake. */ IGNITE_HANDSHAKE, + /** Ignite handshake response. */ + IGNITE_HANDSHAKE_RES, + /** Ignite message. */ IGNITE } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessage.java index 707383f09ea2f..a42fb577ebc9b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessage.java @@ -51,6 +51,9 @@ public class GridMemcachedMessage implements GridClientMessage { /** Client handshake flag. */ public static final byte IGNITE_HANDSHAKE_FLAG = (byte)0x91; + /** Client handshake flag. */ + public static final byte IGNITE_HANDSHAKE_RES_FLAG = (byte)0x92; + /** Success status. */ public static final int SUCCESS = 0x0000; 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 deleted file mode 100644 index a58d5eeb4d4a1..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.marshaller.*; - -import java.io.*; -import java.nio.*; -import java.nio.charset.*; -import java.util.*; - -import static org.apache.ignite.internal.processors.rest.protocols.tcp.GridMemcachedMessage.*; - -/** - * Memcached message wrapper for direct marshalling. - */ -public class GridMemcachedMessageWrapper extends GridTcpCommunicationMessageAdapter { - /** */ - private static final long serialVersionUID = 3053626103006980626L; - - /** UTF-8 charset. */ - private static final Charset UTF_8 = Charset.forName("UTF-8"); - - /** - * Memcached message bytes. - */ - private byte[] bytes; - - /** - * - */ - public GridMemcachedMessageWrapper() { - // No-op. - } - - /** - * @param msg Message. - * @param jdkMarshaller JDK marshaller. - * @throws IgniteCheckedException If failed to marshal. - */ - public GridMemcachedMessageWrapper(GridMemcachedMessage msg, Marshaller jdkMarshaller) throws IgniteCheckedException { - bytes = encodeMemcache(msg, jdkMarshaller); - } - - /** {@inheritDoc} */ - @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!commState.typeWritten) { - if (!commState.putByte(directType())) - return false; - - commState.typeWritten = true; - } - - switch (commState.idx) { - case 0: - if (!commState.putByteArrayClient(bytes)) - return false; - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean readFrom(ByteBuffer buf) { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return MEMCACHE_RES_FLAG; - } - - /** {@inheritDoc} */ - @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { - GridMemcachedMessageWrapper _clone = new GridMemcachedMessageWrapper(); - - clone0(_clone); - - return _clone; - } - - /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - GridMemcachedMessageWrapper _clone = (GridMemcachedMessageWrapper)_msg; - - _clone.bytes = bytes; - } - - /** - * Encodes memcache message to a raw byte array. - * - * @param msg Message being serialized. - * @param jdkMarshaller JDK marshaller. - * @return Serialized message. - * @throws IgniteCheckedException If serialization failed. - */ - private byte[] encodeMemcache(GridMemcachedMessage msg, Marshaller jdkMarshaller) throws IgniteCheckedException { - GridByteArrayList res = new GridByteArrayList(HDR_LEN - 1); - - int keyLen = 0; - - int keyFlags = 0; - - if (msg.key() != null) { - ByteArrayOutputStream rawKey = new ByteArrayOutputStream(); - - keyFlags = encodeObj(msg.key(), rawKey, jdkMarshaller); - - msg.key(rawKey.toByteArray()); - - keyLen = rawKey.size(); - } - - int dataLen = 0; - - int valFlags = 0; - - if (msg.value() != null) { - ByteArrayOutputStream rawVal = new ByteArrayOutputStream(); - - valFlags = encodeObj(msg.value(), rawVal, jdkMarshaller); - - msg.value(rawVal.toByteArray()); - - dataLen = rawVal.size(); - } - - int flagsLen = 0; - - if (msg.addFlags()) - flagsLen = FLAGS_LENGTH; - - res.add(msg.operationCode()); - - // Cast is required due to packet layout. - res.add((short)keyLen); - - // Cast is required due to packet layout. - res.add((byte)flagsLen); - - // Data type is always 0x00. - res.add((byte)0x00); - - res.add((short)msg.status()); - - res.add(keyLen + flagsLen + dataLen); - - res.add(msg.opaque(), 0, msg.opaque().length); - - // CAS, unused. - res.add(0L); - - assert res.size() == HDR_LEN - 1; - - if (flagsLen > 0) { - res.add((short) keyFlags); - res.add((short) valFlags); - } - - assert msg.key() == null || msg.key() instanceof byte[]; - assert msg.value() == null || msg.value() instanceof byte[]; - - if (keyLen > 0) - res.add((byte[])msg.key(), 0, ((byte[])msg.key()).length); - - if (dataLen > 0) - res.add((byte[])msg.value(), 0, ((byte[])msg.value()).length); - - return res.entireArray(); - } - - /** - * Encodes given object to a byte array and returns flags that describe the type of serialized object. - * - * @param obj Object to serialize. - * @param out Output stream to which object should be written. - * @param jdkMarshaller JDK marshaller. - * @return Serialization flags. - * @throws IgniteCheckedException If JDK serialization failed. - */ - private int encodeObj(Object obj, ByteArrayOutputStream out, Marshaller jdkMarshaller) throws IgniteCheckedException { - int flags = 0; - - byte[] data = null; - - if (obj instanceof String) - data = ((String)obj).getBytes(UTF_8); - else if (obj instanceof Boolean) { - data = new byte[] {(byte)((Boolean)obj ? '1' : '0')}; - - flags |= BOOLEAN_FLAG; - } - else if (obj instanceof Integer) { - data = U.intToBytes((Integer) obj); - - flags |= INT_FLAG; - } - else if (obj instanceof Long) { - data = U.longToBytes((Long)obj); - - flags |= LONG_FLAG; - } - else if (obj instanceof Date) { - data = U.longToBytes(((Date)obj).getTime()); - - flags |= DATE_FLAG; - } - else if (obj instanceof Byte) { - data = new byte[] {(Byte)obj}; - - flags |= BYTE_FLAG; - } - else if (obj instanceof Float) { - data = U.intToBytes(Float.floatToIntBits((Float)obj)); - - flags |= FLOAT_FLAG; - } - else if (obj instanceof Double) { - data = U.longToBytes(Double.doubleToLongBits((Double)obj)); - - flags |= DOUBLE_FLAG; - } - else if (obj instanceof byte[]) { - data = (byte[])obj; - - flags |= BYTE_ARR_FLAG; - } - else { - jdkMarshaller.marshal(obj, out); - - flags |= SERIALIZED_FLAG; - } - - if (data != null) - out.write(data, 0, data.length); - - return flags; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridMemcachedMessageWrapper.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpMemcachedNioListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpMemcachedNioListener.java index 070546ea04525..43e47cd241324 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpMemcachedNioListener.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpMemcachedNioListener.java @@ -244,18 +244,7 @@ public GridTcpMemcachedNioListener(IgniteLogger log, GridRestProtocolHandler hnd * @return NIO send future. */ private GridNioFuture sendResponse(GridNioSession ses, GridMemcachedMessage res) { - try { - GridMemcachedMessageWrapper wrapper = new GridMemcachedMessageWrapper(res, jdkMarshaller); - - return ses.send(wrapper); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to marshal response: " + res, e); - - ses.close(); - - return new GridNioFinishedFuture<>(e); - } + return ses.send(res); } /** 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 deleted file mode 100644 index 55d7c95c44bd0..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestDirectParser.java +++ /dev/null @@ -1,519 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp; - -import org.apache.ignite.*; -import org.apache.ignite.client.marshaller.*; -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.jetbrains.annotations.*; - -import java.io.*; -import java.nio.*; -import java.nio.charset.*; -import java.util.*; - -import static org.apache.ignite.internal.processors.rest.protocols.tcp.GridMemcachedMessage.*; -import static org.apache.ignite.internal.util.nio.GridNioSessionMetaKey.*; - -/** - * - */ -public class GridTcpRestDirectParser implements GridNioParser { - /** UTF-8 charset. */ - private static final Charset UTF_8 = Charset.forName("UTF-8"); - - /** Message metadata key. */ - private static final int MSG_META_KEY = GridNioSessionMetaKey.nextUniqueKey(); - - /** Protocol handler. */ - private final GridTcpRestProtocol proto; - - /** Message reader. */ - private final GridNioMessageReader msgReader; - - /** - * @param proto Protocol handler. - * @param msgReader Message reader. - */ - public GridTcpRestDirectParser(GridTcpRestProtocol proto, GridNioMessageReader msgReader) { - this.proto = proto; - this.msgReader = msgReader; - } - - /** {@inheritDoc} */ - @Nullable @Override public Object decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException { - ParserState state = ses.removeMeta(PARSER_STATE.ordinal()); - - if (state != null) { - assert state.packetType() == GridClientPacketType.MEMCACHE; - - Object memcacheMsg = parseMemcachePacket(ses, buf, state); - - if (memcacheMsg == null) - ses.addMeta(PARSER_STATE.ordinal(), state); - - return memcacheMsg; - } - - GridTcpCommunicationMessageAdapter msg = ses.removeMeta(MSG_META_KEY); - - if (msg == null && buf.hasRemaining()) { - byte type = buf.get(buf.position()); - - if (type == GridClientMessageWrapper.REQ_HEADER) { - buf.get(); - - msg = new GridClientMessageWrapper(); - } - else if (type == GridClientHandshakeRequestWrapper.HANDSHAKE_HEADER) { - buf.get(); - - msg = new GridClientHandshakeRequestWrapper(); - } - else if (type == MEMCACHE_REQ_FLAG) { - state = new ParserState(); - - state.packet(new GridMemcachedMessage()); - state.packetType(GridClientPacketType.MEMCACHE); - - Object memcacheMsg = parseMemcachePacket(ses, buf, state); - - if (memcacheMsg == null) - ses.addMeta(PARSER_STATE.ordinal(), state); - - return memcacheMsg; - } - else - throw new IOException("Invalid message type: " + type); - } - - boolean finished = false; - - if (buf.hasRemaining()) - finished = msgReader.read(null, msg, buf); - - if (finished) { - if (msg instanceof GridClientMessageWrapper) { - GridClientMessageWrapper clientMsg = (GridClientMessageWrapper)msg; - - if (clientMsg.messageSize() == 0) - return GridClientPingPacket.PING_MESSAGE; - - GridClientMarshaller marsh = proto.marshaller(ses); - - GridClientMessage ret = marsh.unmarshal(clientMsg.messageArray()); - - ret.requestId(clientMsg.requestId()); - ret.clientId(clientMsg.clientId()); - ret.destinationId(clientMsg.destinationId()); - - return ret; - } - else { - assert msg instanceof GridClientHandshakeRequestWrapper; - - GridClientHandshakeRequestWrapper req = (GridClientHandshakeRequestWrapper)msg; - - GridClientHandshakeRequest ret = new GridClientHandshakeRequest(); - - ret.putBytes(req.bytes(), 0, 4); - - return ret; - } - } - else { - ses.addMeta(MSG_META_KEY, msg); - - return null; - } - } - - /** {@inheritDoc} */ - @Override public ByteBuffer encode(GridNioSession ses, Object msg) throws IOException, IgniteCheckedException { - // No encoding needed for direct messages. - throw new UnsupportedEncodingException(); - } - - /** - * Parses memcache protocol message. - * - * @param ses Session. - * @param buf Buffer containing not parsed bytes. - * @param state Current parser state. - * @return Parsed packet.s - * @throws IOException If packet cannot be parsed. - * @throws IgniteCheckedException If deserialization error occurred. - */ - @Nullable private GridClientMessage parseMemcachePacket(GridNioSession ses, ByteBuffer buf, ParserState state) - throws IOException, IgniteCheckedException { - assert state.packetType() == GridClientPacketType.MEMCACHE; - assert state.packet() != null; - assert state.packet() instanceof GridMemcachedMessage; - - GridMemcachedMessage req = (GridMemcachedMessage)state.packet(); - ByteArrayOutputStream tmp = state.buffer(); - int i = state.index(); - - while (buf.remaining() > 0) { - byte b = buf.get(); - - if (i == 0) - req.requestFlag(b); - else if (i == 1) - req.operationCode(b); - else if (i == 2 || i == 3) { - tmp.write(b); - - if (i == 3) { - req.keyLength(U.bytesToShort(tmp.toByteArray(), 0)); - - tmp.reset(); - } - } - else if (i == 4) - req.extrasLength(b); - else if (i >= 8 && i <= 11) { - tmp.write(b); - - if (i == 11) { - req.totalLength(U.bytesToInt(tmp.toByteArray(), 0)); - - tmp.reset(); - } - } - else if (i >= 12 && i <= 15) { - tmp.write(b); - - if (i == 15) { - req.opaque(tmp.toByteArray()); - - tmp.reset(); - } - } - else if (i >= HDR_LEN && i < HDR_LEN + req.extrasLength()) { - tmp.write(b); - - if (i == HDR_LEN + req.extrasLength() - 1) { - req.extras(tmp.toByteArray()); - - tmp.reset(); - } - } - else if (i >= HDR_LEN + req.extrasLength() && - i < HDR_LEN + req.extrasLength() + req.keyLength()) { - tmp.write(b); - - if (i == HDR_LEN + req.extrasLength() + req.keyLength() - 1) { - req.key(tmp.toByteArray()); - - tmp.reset(); - } - } - else if (i >= HDR_LEN + req.extrasLength() + req.keyLength() && - i < HDR_LEN + req.totalLength()) { - tmp.write(b); - - if (i == HDR_LEN + req.totalLength() - 1) { - req.value(tmp.toByteArray()); - - tmp.reset(); - } - } - - if (i == HDR_LEN + req.totalLength() - 1) - // Assembled the packet. - return assemble(ses, req); - - i++; - } - - state.index(i); - - return null; - } - - /** - * Validates incoming packet and deserializes all fields that need to be deserialized. - * - * @param ses Session on which packet is being parsed. - * @param req Raw packet. - * @return Same packet with fields deserialized. - * @throws IOException If parsing failed. - * @throws IgniteCheckedException If deserialization failed. - */ - private GridClientMessage assemble(GridNioSession ses, GridMemcachedMessage req) throws IOException, IgniteCheckedException { - byte[] extras = req.extras(); - - // First, decode key and value, if any - if (req.key() != null || req.value() != null) { - short keyFlags = 0; - short valFlags = 0; - - if (req.hasFlags()) { - if (extras == null || extras.length < FLAGS_LENGTH) - throw new IOException("Failed to parse incoming packet (flags required for command) [ses=" + - ses + ", opCode=" + Integer.toHexString(req.operationCode() & 0xFF) + ']'); - - keyFlags = U.bytesToShort(extras, 0); - valFlags = U.bytesToShort(extras, 2); - } - - if (req.key() != null) { - assert req.key() instanceof byte[]; - - byte[] rawKey = (byte[])req.key(); - - // Only values can be hessian-encoded. - req.key(decodeObj(keyFlags, rawKey)); - } - - if (req.value() != null) { - assert req.value() instanceof byte[]; - - byte[] rawVal = (byte[])req.value(); - - req.value(decodeObj(valFlags, rawVal)); - } - } - - if (req.hasExpiration()) { - if (extras == null || extras.length < 8) - throw new IOException("Failed to parse incoming packet (expiration value required for command) [ses=" + - ses + ", opCode=" + Integer.toHexString(req.operationCode() & 0xFF) + ']'); - - req.expiration(U.bytesToInt(extras, 4) & 0xFFFFFFFFL); - } - - if (req.hasInitial()) { - if (extras == null || extras.length < 16) - throw new IOException("Failed to parse incoming packet (initial value required for command) [ses=" + - ses + ", opCode=" + Integer.toHexString(req.operationCode() & 0xFF) + ']'); - - req.initial(U.bytesToLong(extras, 8)); - } - - if (req.hasDelta()) { - if (extras == null || extras.length < 8) - throw new IOException("Failed to parse incoming packet (delta value required for command) [ses=" + - ses + ", opCode=" + Integer.toHexString(req.operationCode() & 0xFF) + ']'); - - req.delta(U.bytesToLong(extras, 0)); - } - - if (extras != null) { - // Clients that include cache name must always include flags. - int len = 4; - - if (req.hasExpiration()) - len += 4; - - if (req.hasDelta()) - len += 8; - - if (req.hasInitial()) - len += 8; - - if (extras.length - len > 0) { - byte[] cacheName = new byte[extras.length - len]; - - U.arrayCopy(extras, len, cacheName, 0, extras.length - len); - - req.cacheName(new String(cacheName, UTF_8)); - } - } - - return req; - } - - /** - * Decodes value from a given byte array to the object according to the flags given. - * - * @param flags Flags. - * @param bytes Byte array to decode. - * @return Decoded value. - * @throws IgniteCheckedException If deserialization failed. - */ - private Object decodeObj(short flags, byte[] bytes) throws IgniteCheckedException { - assert bytes != null; - - if ((flags & SERIALIZED_FLAG) != 0) - return proto.jdkMarshaller().unmarshal(bytes, null); - - int masked = flags & 0xff00; - - switch (masked) { - case BOOLEAN_FLAG: - return bytes[0] == '1'; - case INT_FLAG: - return U.bytesToInt(bytes, 0); - case LONG_FLAG: - return U.bytesToLong(bytes, 0); - case DATE_FLAG: - return new Date(U.bytesToLong(bytes, 0)); - case BYTE_FLAG: - return bytes[0]; - case FLOAT_FLAG: - return Float.intBitsToFloat(U.bytesToInt(bytes, 0)); - case DOUBLE_FLAG: - return Double.longBitsToDouble(U.bytesToLong(bytes, 0)); - case BYTE_ARR_FLAG: - return bytes; - default: - return new String(bytes, UTF_8); - } - } - - /** - * Holder for parser state and temporary buffer. - */ - protected static class ParserState { - /** Parser index. */ - private int idx; - - /** Temporary data buffer. */ - private ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - /** Packet being assembled. */ - private GridClientMessage packet; - - /** Packet type. */ - private GridClientPacketType packetType; - - /** Header data. */ - private HeaderData hdr; - - /** - * @return Stored parser index. - */ - public int index() { - return idx; - } - - /** - * @param idx Index to store. - */ - public void index(int idx) { - this.idx = idx; - } - - /** - * @return Temporary data buffer. - */ - public ByteArrayOutputStream buffer() { - return buf; - } - - /** - * @return Pending packet. - */ - @Nullable public GridClientMessage packet() { - return packet; - } - - /** - * @param packet Pending packet. - */ - public void packet(GridClientMessage packet) { - assert this.packet == null; - - this.packet = packet; - } - - /** - * @return Pending packet type. - */ - public GridClientPacketType packetType() { - return packetType; - } - - /** - * @param packetType Pending packet type. - */ - public void packetType(GridClientPacketType packetType) { - this.packetType = packetType; - } - - /** - * @return Header. - */ - public HeaderData header() { - return hdr; - } - - /** - * @param hdr Header. - */ - public void header(HeaderData hdr) { - this.hdr = hdr; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(ParserState.class, this); - } - } - - /** - * Header. - */ - protected static class HeaderData { - /** Request Id. */ - private final long reqId; - - /** Request Id. */ - private final UUID clientId; - - /** Request Id. */ - private final UUID destId; - - /** - * @param reqId Request Id. - * @param clientId Client Id. - * @param destId Destination Id. - */ - private HeaderData(long reqId, UUID clientId, UUID destId) { - this.reqId = reqId; - this.clientId = clientId; - this.destId = destId; - } - - /** - * @return Request Id. - */ - public long reqId() { - return reqId; - } - - /** - * @return Client Id. - */ - public UUID clientId() { - return clientId; - } - - /** - * @return Destination Id. - */ - public UUID destinationId() { - return destId; - } - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java index 12dc711268eb7..0394046f4af9e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java @@ -29,14 +29,11 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.jetbrains.annotations.*; -import java.io.*; -import java.nio.*; import java.util.*; import java.util.concurrent.*; import static org.apache.ignite.internal.processors.rest.GridRestCommand.*; import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; -import static org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeResponse.*; import static org.apache.ignite.internal.util.nio.GridNioSessionMetaKey.*; /** @@ -137,8 +134,8 @@ void marshallers(Map marshMap) { if (msg instanceof GridMemcachedMessage) memcachedLsnr.onMessage(ses, (GridMemcachedMessage)msg); else { - if (msg == GridClientPingPacket.PING_MESSAGE) - ses.send(new GridClientPingPacketWrapper()); + if (msg instanceof GridClientPingPacket) + ses.send(msg); else if (msg instanceof GridClientHandshakeRequest) { GridClientHandshakeRequest hs = (GridClientHandshakeRequest)msg; @@ -168,7 +165,7 @@ else if (msg instanceof GridClientHandshakeRequest) { else { ses.addMeta(MARSHALLER.ordinal(), marsh); - ses.send(new GridClientHandshakeResponseWrapper(CODE_OK)); + ses.send(GridClientHandshakeResponse.OK); } } } @@ -205,27 +202,7 @@ else if (msg instanceof GridClientHandshakeRequest) { res.errorMessage("Failed to process client request: " + e.getMessage()); } - GridClientMessageWrapper wrapper = new GridClientMessageWrapper(); - - wrapper.requestId(msg.requestId()); - wrapper.clientId(msg.clientId()); - - try { - ByteBuffer bytes = proto.marshaller(ses).marshal(res, 0); - - wrapper.message(bytes); - - wrapper.messageSize(bytes.remaining() + 40); - } - catch (IOException e) { - U.error(log, "Failed to marshal response: " + res, e); - - ses.close(); - - return; - } - - ses.send(wrapper); + ses.send(res); } }); else @@ -313,20 +290,6 @@ else if (msg instanceof GridClientTaskRequest) { restReq = restTaskReq; } - else if (msg instanceof GridClientGetMetaDataRequest) { - GridClientGetMetaDataRequest req = (GridClientGetMetaDataRequest)msg; - - restReq = new GridRestPortableGetMetaDataRequest(req); - - restReq.command(GET_PORTABLE_METADATA); - } - else if (msg instanceof GridClientPutMetaDataRequest) { - GridClientPutMetaDataRequest req = (GridClientPutMetaDataRequest)msg; - - restReq = new GridRestPortablePutMetaDataRequest(req); - - restReq.command(PUT_PORTABLE_METADATA); - } else if (msg instanceof GridClientTopologyRequest) { GridClientTopologyRequest req = (GridClientTopologyRequest) msg; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestParser.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestParser.java index d94b598369907..3a83d4b0787cb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestParser.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestParser.java @@ -45,6 +45,16 @@ public class GridTcpRestParser implements GridNioParser { /** JDK marshaller. */ private final Marshaller jdkMarshaller = new JdkMarshaller(); + /** Router client flag. */ + private final boolean routerClient; + + /** + * @param routerClient Router client flag. + */ + public GridTcpRestParser(boolean routerClient) { + this.routerClient = routerClient; + } + /** {@inheritDoc} */ @Nullable @Override public GridClientMessage decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException { @@ -81,6 +91,13 @@ public class GridTcpRestParser implements GridNioParser { break; + case IGNITE_HANDSHAKE_RES_FLAG: + buf.get(); + + state.packetType(GridClientPacketType.IGNITE_HANDSHAKE_RES); + + break; + default: throw new IOException("Failed to parse incoming packet (invalid packet start) [ses=" + ses + ", b=" + Integer.toHexString(hdr & 0xFF) + ']'); @@ -100,6 +117,12 @@ public class GridTcpRestParser implements GridNioParser { break; + case IGNITE_HANDSHAKE_RES: + if (buf.hasRemaining()) + res = new GridClientHandshakeResponse(buf.get()); + + break; + case IGNITE: res = parseCustomPacket(ses, buf, state); @@ -121,12 +144,41 @@ public class GridTcpRestParser implements GridNioParser { if (msg instanceof GridMemcachedMessage) return encodeMemcache((GridMemcachedMessage)msg); - else if (msg == GridClientPingPacket.PING_MESSAGE) + else if (msg instanceof GridClientPingPacket) return ByteBuffer.wrap(GridClientPingPacket.PING_PACKET); + else if (msg instanceof GridClientHandshakeRequest) { + byte[] bytes = ((GridClientHandshakeRequest)msg).rawBytes(); + + ByteBuffer buf = ByteBuffer.allocate(bytes.length + 1); + + buf.put(IGNITE_HANDSHAKE_FLAG); + buf.put(bytes); + + buf.flip(); + + return buf; + } else if (msg instanceof GridClientHandshakeResponse) return ByteBuffer.wrap(new byte[] { + IGNITE_HANDSHAKE_RES_FLAG, ((GridClientHandshakeResponse)msg).resultCode() }); + else if (msg instanceof GridRouterRequest) { + byte[] body = ((GridRouterRequest)msg).body(); + + ByteBuffer buf = ByteBuffer.allocate(45 + body.length); + + buf.put(IGNITE_REQ_FLAG); + buf.putInt(40 + body.length); + buf.putLong(msg.requestId()); + buf.put(U.uuidToBytes(msg.clientId())); + buf.put(U.uuidToBytes(msg.destinationId())); + buf.put(body); + + buf.flip(); + + return buf; + } else { GridClientMarshaller marsh = marshaller(ses); @@ -429,13 +481,24 @@ private void copyRemaining(ByteBuffer src, OutputStream dest) throws IOException * @throws IgniteCheckedException If no marshaller was defined for the session. */ protected GridClientMessage parseClientMessage(GridNioSession ses, ParserState state) throws IOException, IgniteCheckedException { - GridClientMarshaller marsh = marshaller(ses); + GridClientMessage msg; - GridClientMessage msg = marsh.unmarshal(state.buffer().toByteArray()); + if (routerClient) { + msg = new GridRouterResponse( + state.buffer().toByteArray(), + state.header().reqId(), + state.header().clientId(), + state.header().destinationId()); + } + else { + GridClientMarshaller marsh = marshaller(ses); + + msg = marsh.unmarshal(state.buffer().toByteArray()); - msg.requestId(state.header().reqId()); - msg.clientId(state.header().clientId()); - msg.destinationId(state.header().destinationId()); + msg.requestId(state.header().reqId()); + msg.clientId(state.header().clientId()); + msg.destinationId(state.header().destinationId()); + } return msg; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java index 1740ecd6c7053..7482a799c2eb3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java @@ -27,7 +27,6 @@ import org.apache.ignite.internal.processors.rest.*; import org.apache.ignite.internal.processors.rest.client.message.*; import org.apache.ignite.internal.processors.rest.protocols.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.nio.ssl.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -57,59 +56,6 @@ public class GridTcpRestProtocol extends GridRestProtocolAdapter { /** NIO server listener. */ private GridTcpRestNioListener lsnr; - /** Message reader. */ - private final GridNioMessageReader msgReader = new GridNioMessageReader() { - @Override public boolean read(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, ByteBuffer buf) { - assert msg != null; - assert buf != null; - - msg.messageReader(this, nodeId); - - return msg.readFrom(buf); - } - - @Nullable @Override public GridTcpMessageFactory messageFactory() { - return null; - } - }; - - /** Message writer. */ - private final GridNioMessageWriter msgWriter = new GridNioMessageWriter() { - @Override public boolean write(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, ByteBuffer buf) { - assert msg != null; - assert buf != null; - - msg.messageWriter(this, nodeId); - - return msg.writeTo(buf); - } - - @Override public int writeFully(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, OutputStream out, - ByteBuffer buf) throws IOException { - assert msg != null; - assert out != null; - assert buf != null; - assert buf.hasArray(); - - msg.messageWriter(this, nodeId); - - boolean finished = false; - int cnt = 0; - - while (!finished) { - finished = msg.writeTo(buf); - - out.write(buf.array(), 0, buf.position()); - - cnt += buf.position(); - - buf.clear(); - } - - return cnt; - } - }; - /** @param ctx Context. */ public GridTcpRestProtocol(GridKernalContext ctx) { super(ctx); @@ -160,7 +106,7 @@ boolean portableMode(GridNioSession ses) { lsnr = new GridTcpRestNioListener(log, this, hnd, ctx); - GridNioParser parser = new GridTcpRestDirectParser(this, msgReader); + GridNioParser parser = new GridTcpRestParser(false); try { host = resolveRestTcpHost(ctx.config()); @@ -261,14 +207,14 @@ private InetAddress resolveRestTcpHost(IgniteConfiguration cfg) throws IOExcepti private boolean startTcpServer(InetAddress hostAddr, int port, GridNioServerListener lsnr, GridNioParser parser, @Nullable SSLContext sslCtx, ClientConnectionConfiguration cfg) { try { - GridNioFilter codec = new GridNioCodecFilter(parser, log, true); + GridNioFilter codec = new GridNioCodecFilter(parser, log, false); GridNioFilter[] filters; if (sslCtx != null) { GridNioSslFilter sslFilter = new GridNioSslFilter(sslCtx, log); - sslFilter.directMode(true); + sslFilter.directMode(false); boolean auth = cfg.isRestTcpSslClientAuth(); @@ -298,8 +244,7 @@ private boolean startTcpServer(InetAddress hostAddr, int port, GridNioServerList .socketReceiveBufferSize(cfg.getRestTcpReceiveBufferSize()) .sendQueueLimit(cfg.getRestTcpSendQueueLimit()) .filters(filters) - .directMode(true) - .messageWriter(msgWriter) + .directMode(false) .build(); srv.idleTimeout(cfg.getRestIdleTimeout()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestPortableGetMetaDataRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestPortableGetMetaDataRequest.java deleted file mode 100644 index 6205a0ea568ce..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestPortableGetMetaDataRequest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.request; - -import org.apache.ignite.internal.processors.rest.client.message.*; - -import java.util.*; - -/** - * Portable get metadata request. - */ -public class GridRestPortableGetMetaDataRequest extends GridRestRequest { - /** */ - private final GridClientGetMetaDataRequest msg; - - /** - * @param msg Client message. - */ - public GridRestPortableGetMetaDataRequest(GridClientGetMetaDataRequest msg) { - this.msg = msg; - } - - /** - * @return Type IDs. - */ - public Collection typeIds() { - return msg.typeIds(); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestPortablePutMetaDataRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestPortablePutMetaDataRequest.java deleted file mode 100644 index 7acee3932536b..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestPortablePutMetaDataRequest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.request; - -import org.apache.ignite.internal.processors.rest.client.message.*; - -import java.util.*; - -/** - * Portable get metadata request. - */ -public class GridRestPortablePutMetaDataRequest extends GridRestRequest { - /** */ - private final GridClientPutMetaDataRequest msg; - - /** - * @param msg Client message. - */ - public GridRestPortablePutMetaDataRequest(GridClientPutMetaDataRequest msg) { - this.msg = msg; - } - - /** - * @return Type IDs. - */ - public Collection metaData() { - return msg.metaData(); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerCancelRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerCancelRequest.java index f81c3a876c82d..4f67c3abee23d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerCancelRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerCancelRequest.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.processors.streamer; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -26,7 +26,7 @@ /** * Streamer cancel request. */ -public class GridStreamerCancelRequest extends GridTcpCommunicationMessageAdapter { +public class GridStreamerCancelRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -56,7 +56,7 @@ public IgniteUuid cancelledFutureId() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridStreamerCancelRequest _clone = new GridStreamerCancelRequest(); clone0(_clone); @@ -65,7 +65,7 @@ public IgniteUuid cancelledFutureId() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridStreamerCancelRequest _clone = (GridStreamerCancelRequest)_msg; _clone.cancelledFutId = cancelledFutId; @@ -74,21 +74,21 @@ public IgniteUuid cancelledFutureId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putGridUuid(cancelledFutId)) + if (!writer.writeIgniteUuid("cancelledFutId", cancelledFutId)) return false; - commState.idx++; + state++; } @@ -98,18 +98,16 @@ public IgniteUuid cancelledFutureId() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - IgniteUuid cancelledFutId0 = commState.getGridUuid(); + cancelledFutId = reader.readIgniteUuid("cancelledFutId"); - if (cancelledFutId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - cancelledFutId = cancelledFutId0; - - commState.idx++; + state++; } @@ -118,6 +116,6 @@ public IgniteUuid cancelledFutureId() { /** {@inheritDoc} */ @Override public byte directType() { - return 75; + return 79; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerExecutionRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerExecutionRequest.java index ed06ecdb74abf..a4bc2bb9a56f4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerExecutionRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerExecutionRequest.java @@ -19,10 +19,10 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.nio.*; @@ -31,7 +31,7 @@ /** * */ -public class GridStreamerExecutionRequest extends GridTcpCommunicationMessageAdapter { +public class GridStreamerExecutionRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -151,7 +151,7 @@ public byte[] batchBytes() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridStreamerExecutionRequest _clone = new GridStreamerExecutionRequest(); clone0(_clone); @@ -160,7 +160,7 @@ public byte[] batchBytes() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridStreamerExecutionRequest _clone = (GridStreamerExecutionRequest)_msg; _clone.forceLocDep = forceLocDep; @@ -175,89 +175,57 @@ public byte[] batchBytes() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(batchBytes)) + if (!writer.writeByteArray("batchBytes", batchBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(clsLdrId)) + if (!writer.writeIgniteUuid("clsLdrId", clsLdrId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putEnum(depMode)) + if (!writer.writeEnum("depMode", depMode)) return false; - commState.idx++; + state++; case 3: - if (!commState.putBoolean(forceLocDep)) + if (!writer.writeBoolean("forceLocDep", forceLocDep)) return false; - commState.idx++; + state++; case 4: - if (ldrParticipants != null) { - if (commState.it == null) { - if (!commState.putInt(ldrParticipants.size())) - return false; - - commState.it = ldrParticipants.entrySet().iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - Map.Entry e = (Map.Entry)commState.cur; - - if (!commState.keyDone) { - if (!commState.putUuid(e.getKey())) - return false; - - commState.keyDone = true; - } - - if (!commState.putGridUuid(e.getValue())) - return false; - - commState.keyDone = false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } + if (!writer.writeMap("ldrParticipants", ldrParticipants, UUID.class, IgniteUuid.class)) + return false; - commState.idx++; + state++; case 5: - if (!commState.putString(sampleClsName)) + if (!writer.writeString("sampleClsName", sampleClsName)) return false; - commState.idx++; + state++; case 6: - if (!commState.putString(userVer)) + if (!writer.writeString("userVer", userVer)) return false; - commState.idx++; + state++; } @@ -267,108 +235,64 @@ public byte[] batchBytes() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - byte[] batchBytes0 = commState.getByteArray(); + batchBytes = reader.readByteArray("batchBytes"); - if (batchBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - batchBytes = batchBytes0; - - commState.idx++; + state++; case 1: - IgniteUuid clsLdrId0 = commState.getGridUuid(); + clsLdrId = reader.readIgniteUuid("clsLdrId"); - if (clsLdrId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - clsLdrId = clsLdrId0; - - commState.idx++; + state++; case 2: - if (buf.remaining() < 1) - return false; - - byte depMode0 = commState.getByte(); + depMode = reader.readEnum("depMode", DeploymentMode.class); - depMode = DeploymentMode.fromOrdinal(depMode0); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - if (buf.remaining() < 1) - return false; + forceLocDep = reader.readBoolean("forceLocDep"); - forceLocDep = commState.getBoolean(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 4: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (ldrParticipants == null) - ldrParticipants = U.newHashMap(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - if (!commState.keyDone) { - UUID _val = commState.getUuid(); - - if (_val == UUID_NOT_READ) - return false; - - commState.cur = _val; - commState.keyDone = true; - } - - IgniteUuid _val = commState.getGridUuid(); + ldrParticipants = reader.readMap("ldrParticipants", UUID.class, IgniteUuid.class, false); - if (_val == GRID_UUID_NOT_READ) - return false; - - ldrParticipants.put((UUID)commState.cur, _val); - - commState.keyDone = false; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - commState.cur = null; + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 5: - String sampleClsName0 = commState.getString(); + sampleClsName = reader.readString("sampleClsName"); - if (sampleClsName0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - sampleClsName = sampleClsName0; - - commState.idx++; + state++; case 6: - String userVer0 = commState.getString(); + userVer = reader.readString("userVer"); - if (userVer0 == STR_NOT_READ) + if (!reader.isLastRead()) return false; - userVer = userVer0; - - commState.idx++; + state++; } @@ -377,6 +301,6 @@ public byte[] batchBytes() { /** {@inheritDoc} */ @Override public byte directType() { - return 76; + return 80; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerResponse.java index 92b46c785fb15..fc6da7fa8f74d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/GridStreamerResponse.java @@ -17,9 +17,9 @@ package org.apache.ignite.internal.processors.streamer; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.nio.*; @@ -27,7 +27,7 @@ /** * */ -public class GridStreamerResponse extends GridTcpCommunicationMessageAdapter { +public class GridStreamerResponse extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -76,7 +76,7 @@ public byte[] errorBytes() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridStreamerResponse _clone = new GridStreamerResponse(); clone0(_clone); @@ -85,7 +85,7 @@ public byte[] errorBytes() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridStreamerResponse _clone = (GridStreamerResponse)_msg; _clone.futId = futId; @@ -95,27 +95,27 @@ public byte[] errorBytes() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putByteArray(errBytes)) + if (!writer.writeByteArray("errBytes", errBytes)) return false; - commState.idx++; + state++; case 1: - if (!commState.putGridUuid(futId)) + if (!writer.writeIgniteUuid("futId", futId)) return false; - commState.idx++; + state++; } @@ -125,28 +125,24 @@ public byte[] errorBytes() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - byte[] errBytes0 = commState.getByteArray(); + errBytes = reader.readByteArray("errBytes"); - if (errBytes0 == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - errBytes = errBytes0; - - commState.idx++; + state++; case 1: - IgniteUuid futId0 = commState.getGridUuid(); + futId = reader.readIgniteUuid("futId"); - if (futId0 == GRID_UUID_NOT_READ) + if (!reader.isLastRead()) return false; - futId = futId0; - - commState.idx++; + state++; } @@ -155,6 +151,6 @@ public byte[] errorBytes() { /** {@inheritDoc} */ @Override public byte directType() { - return 77; + return 81; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/IgniteStreamerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/IgniteStreamerImpl.java index 0af18a1906cbb..7ca3f9b5f4c37 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/IgniteStreamerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/streamer/IgniteStreamerImpl.java @@ -25,7 +25,6 @@ import org.apache.ignite.internal.managers.deployment.*; import org.apache.ignite.internal.managers.eventstorage.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.future.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.tostring.*; @@ -33,6 +32,7 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.worker.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.streamer.*; import org.apache.ignite.streamer.router.*; import org.apache.ignite.thread.*; @@ -1037,7 +1037,7 @@ private void unwindUndeploys(ClassLoader undeployedClsLdr, boolean info) { * @return Execution request. * @throws IgniteCheckedException If failed. */ - private GridTcpCommunicationMessageAdapter createExecutionRequest(GridStreamerExecutionBatch batch) + private MessageAdapter createExecutionRequest(GridStreamerExecutionBatch batch) throws IgniteCheckedException { boolean depEnabled = ctx.deploy().enabled(); @@ -1111,7 +1111,7 @@ private GridStreamerExecutionBatch executionBatch(UUID nodeId, GridStreamerExecu * @param msg Message to send. * @throws IgniteCheckedException If failed. */ - private void sendWithRetries(UUID dstNodeId, GridTcpCommunicationMessageAdapter msg) throws IgniteCheckedException { + private void sendWithRetries(UUID dstNodeId, MessageAdapter msg) throws IgniteCheckedException { for (int i = 0; i < SEND_RETRY_COUNT; i++) { try { ctx.io().send(dstNodeId, topic, msg, GridIoPolicy.SYSTEM_POOL); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/version/GridVersionConverter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/version/GridVersionConverter.java deleted file mode 100644 index ef7a4df29419f..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/version/GridVersionConverter.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.version; - -import org.apache.ignite.internal.util.direct.*; - -import java.nio.*; - -/** - * Version converter. - */ -public abstract class GridVersionConverter { - /** State. */ - protected final GridTcpCommunicationMessageState commState = new GridTcpCommunicationMessageState(); - - /** - * Writes delta between two versions. - * - * @param buf Buffer to write to. - * @return Whether delta was fully written. - */ - public abstract boolean writeTo(ByteBuffer buf); - - /** - * Reads delta between two versions. - * - * @param buf Buffer to read from. - * @return Whether delta was fully read. - */ - public abstract boolean readFrom(ByteBuffer buf); -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridByteArrayList.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridByteArrayList.java index a9b7ffc632562..d9252a1452042 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridByteArrayList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridByteArrayList.java @@ -20,6 +20,7 @@ import org.apache.ignite.internal.util.io.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -28,7 +29,7 @@ /** * Re-sizable array implementation of the byte list (eliminating auto-boxing of primitive byte type). */ -public class GridByteArrayList implements Externalizable { +public class GridByteArrayList extends MessageAdapter implements Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -405,6 +406,84 @@ public InputStream inputStream() { in.readFully(data, 0, size); } + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf) { + writer.setBuffer(buf); + + if (!typeWritten) { + if (!writer.writeByte(null, directType())) + return false; + + typeWritten = true; + } + + switch (state) { + case 0: + if (!writer.writeByteArray("data", data)) + return false; + + state++; + + case 1: + if (!writer.writeInt("size", size)) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf) { + reader.setBuffer(buf); + + switch (state) { + case 0: + data = reader.readByteArray("data"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 1: + size = reader.readInt("size"); + + if (!reader.isLastRead()) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public byte directType() { + return 84; + } + + /** {@inheritDoc} */ + @SuppressWarnings("CloneDoesntCallSuperClone") + @Override public MessageAdapter clone() { + GridByteArrayList _clone = new GridByteArrayList(); + + clone0(_clone); + + return _clone; + } + + /** {@inheritDoc} */ + @Override protected void clone0(MessageAdapter _msg) { + GridByteArrayList _clone = (GridByteArrayList)_msg; + + _clone.data = data; + _clone.size = size; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridByteArrayList.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridClientByteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridClientByteUtils.java index f15e13bf10afd..1c7cbd92e25ef 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridClientByteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridClientByteUtils.java @@ -106,7 +106,7 @@ public static int longToBytes(long l, byte[] bytes, int off) { * @return Encoded into byte array {@link UUID}. */ public static byte[] uuidToBytes(UUID uuid) { - byte[] bytes = new byte[(Long.SIZE >> 3)* 2]; + byte[] bytes = new byte[(Long.SIZE >> 3) * 2]; uuidToBytes(uuid, bytes, 0); @@ -122,7 +122,6 @@ public static byte[] uuidToBytes(UUID uuid) { * @return Number of bytes overwritten in {@code bytes} array. */ public static int uuidToBytes(UUID uuid, byte[] bytes, int off) { - ByteBuffer buf = ByteBuffer.wrap(bytes, off, 16); buf.order(ByteOrder.BIG_ENDIAN); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridLongList.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridLongList.java index bce75f614353c..731dd5ed593f8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridLongList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridLongList.java @@ -19,16 +19,18 @@ import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; +import java.nio.*; import java.util.*; /** * Minimal list API to work with primitive longs. This list exists * to avoid boxing/unboxing when using standard list from Java. */ -public class GridLongList implements Externalizable { +public class GridLongList extends MessageAdapter implements Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -377,10 +379,14 @@ public int replaceValue(int startIdx, long oldVal, long newVal) { } /** - * @return Internal array. + * @return Array copy. */ - public long[] internalArray() { - return arr; + public long[] array() { + long[] res = new long[idx]; + + System.arraycopy(arr, 0, res, 0, idx); + + return res; } /** {@inheritDoc} */ @@ -497,4 +503,82 @@ public void pop(int cnt) { else idx -= cnt; } + + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf) { + writer.setBuffer(buf); + + if (!typeWritten) { + if (!writer.writeByte(null, directType())) + return false; + + typeWritten = true; + } + + switch (state) { + case 0: + if (!writer.writeLongArray("arr", arr)) + return false; + + state++; + + case 1: + if (!writer.writeInt("idx", idx)) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf) { + reader.setBuffer(buf); + + switch (state) { + case 0: + arr = reader.readLongArray("arr"); + + if (!reader.isLastRead()) + return false; + + state++; + + case 1: + idx = reader.readInt("idx"); + + if (!reader.isLastRead()) + return false; + + state++; + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public byte directType() { + return 85; + } + + /** {@inheritDoc} */ + @SuppressWarnings("CloneDoesntCallSuperClone") + @Override public MessageAdapter clone() { + GridLongList _clone = new GridLongList(); + + clone0(_clone); + + return _clone; + } + + /** {@inheritDoc} */ + @Override protected void clone0(MessageAdapter _msg) { + GridLongList _clone = (GridLongList)_msg; + + _clone.arr = arr; + _clone.idx = idx; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 0e3da0d3ec3c1..cdefbb348e610 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -30,6 +30,10 @@ import org.apache.ignite.internal.mxbean.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.lifecycle.*; +import org.apache.ignite.plugin.extensions.communication.*; +import org.apache.ignite.spi.*; import org.apache.ignite.internal.processors.streamer.*; import org.apache.ignite.internal.transactions.*; import org.apache.ignite.internal.util.io.*; @@ -37,10 +41,6 @@ import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.worker.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.lifecycle.*; -import org.apache.ignite.portables.*; -import org.apache.ignite.spi.*; import org.apache.ignite.spi.discovery.*; import org.apache.ignite.transactions.*; import org.jdk8.backport.*; @@ -65,7 +65,6 @@ import java.security.*; import java.security.cert.*; import java.sql.*; -import java.sql.Timestamp; import java.text.*; import java.util.*; import java.util.Date; @@ -282,9 +281,6 @@ public abstract class IgniteUtils { public static final String MAC_INVALID_ARG_MSG = "On MAC OS you may have too many file descriptors open " + "(simple restart usually solves the issue)"; - /** Portable classes. */ - private static final Collection> PORTABLE_CLS = new HashSet<>(); - /** Ignite Logging Directory. */ public static final String IGNITE_LOG_DIR = System.getenv(IgniteSystemProperties.IGNITE_LOG_DIR); @@ -518,31 +514,6 @@ else if (archStr.contains("sparc")) } } - PORTABLE_CLS.add(Byte.class); - PORTABLE_CLS.add(Short.class); - PORTABLE_CLS.add(Integer.class); - PORTABLE_CLS.add(Long.class); - PORTABLE_CLS.add(Float.class); - PORTABLE_CLS.add(Double.class); - PORTABLE_CLS.add(Character.class); - PORTABLE_CLS.add(Boolean.class); - PORTABLE_CLS.add(String.class); - PORTABLE_CLS.add(UUID.class); - PORTABLE_CLS.add(Date.class); - PORTABLE_CLS.add(Timestamp.class); - PORTABLE_CLS.add(byte[].class); - PORTABLE_CLS.add(short[].class); - PORTABLE_CLS.add(int[].class); - PORTABLE_CLS.add(long[].class); - PORTABLE_CLS.add(float[].class); - PORTABLE_CLS.add(double[].class); - PORTABLE_CLS.add(char[].class); - PORTABLE_CLS.add(boolean[].class); - PORTABLE_CLS.add(String[].class); - PORTABLE_CLS.add(UUID[].class); - PORTABLE_CLS.add(Date[].class); - PORTABLE_CLS.add(Timestamp[].class); - exceptionConverters = Collections.unmodifiableMap(exceptionConverters()); } @@ -4396,7 +4367,7 @@ public static void writeUuid(DataOutput out, UUID uid) throws IOException { long most = in.readLong(); long least = in.readLong(); - return GridUuidCache.onGridUuidRead(new UUID(most, least)); + return IgniteUuidCache.onIgniteUuidRead(new UUID(most, least)); } return null; @@ -4436,7 +4407,7 @@ public static void writeGridUuid(DataOutput out, IgniteUuid uid) throws IOExcept long most = in.readLong(); long least = in.readLong(); - UUID globalId = GridUuidCache.onGridUuidRead(new UUID(most, least)); + UUID globalId = IgniteUuidCache.onIgniteUuidRead(new UUID(most, least)); long locId = in.readLong(); @@ -4446,6 +4417,22 @@ public static void writeGridUuid(DataOutput out, IgniteUuid uid) throws IOExcept return null; } + /** + * Converts GridUuid to bytes. + * + * @param uuid GridUuid to convert. + * @return Bytes. + */ + public static byte[] igniteUuidToBytes(IgniteUuid uuid) { + assert uuid != null; + + byte[] out = new byte[24]; + + igniteUuidToBytes(uuid, out, 0); + + return out; + } + /** * Converts GridUuid to bytes. * @@ -4453,7 +4440,7 @@ public static void writeGridUuid(DataOutput out, IgniteUuid uid) throws IOExcept * @param out Output array to write to. * @param off Offset from which to write. */ - public static void gridUuidToBytes(IgniteUuid uuid, byte[] out, int off) { + public static void igniteUuidToBytes(IgniteUuid uuid, byte[] out, int off) { assert uuid != null; U.longToBytes(uuid.globalId().getMostSignificantBits(), out, off); @@ -4468,12 +4455,12 @@ public static void gridUuidToBytes(IgniteUuid uuid, byte[] out, int off) { * @param off Offset from which start reading. * @return GridUuid instance. */ - public static IgniteUuid bytesToGridUuid(byte[] in, int off) { + public static IgniteUuid bytesToIgniteUuid(byte[] in, int off) { long most = U.bytesToLong(in, off); long least = U.bytesToLong(in, off + 8); long locId = U.bytesToLong(in, off + 16); - return new IgniteUuid(GridUuidCache.onGridUuidRead(new UUID(most, least)), locId); + return new IgniteUuid(IgniteUuidCache.onIgniteUuidRead(new UUID(most, least)), locId); } /** @@ -7188,19 +7175,6 @@ public static GridCacheAttributes[] cacheAttributes(ClusterNode n) { return null; } - /** - * Gets portable enabled flag from the given node for the given cache name. - * - * @param n Node. - * @param cacheName Cache name. - * @return Portable enabled flag. - */ - @Nullable public static Boolean portableEnabled(ClusterNode n, @Nullable String cacheName) { - GridCacheAttributes attrs = cacheAttributes(n, cacheName); - - return attrs == null ? false : attrs.portableEnabled(); - } - /** * Gets view on all cache names started on the node. * @@ -8753,36 +8727,6 @@ public static ClusterNode youngest(Collection c, @Nullable IgnitePr return youngest; } - /** - * Tells whether provided type is portable. - * - * @param cls Class to check. - * @return Whether type is portable. - */ - public static boolean isPortableType(Class cls) { - assert cls != null; - - return PortableObject.class.isAssignableFrom(cls) || - PORTABLE_CLS.contains(cls) || - cls.isEnum() || - (cls.isArray() && cls.getComponentType().isEnum()); - } - /** - * Tells whether provided type is portable or a collection. - * - * @param cls Class to check. - * @return Whether type is portable or a collection. - */ - public static boolean isPortableOrCollectionType(Class cls) { - assert cls != null; - - return isPortableType(cls) || - cls == Object[].class || - Collection.class.isAssignableFrom(cls) || - Map.class.isAssignableFrom(cls) || - Map.Entry.class.isAssignableFrom(cls); - } - /** * @param arr Array. * @param off Offset. @@ -9193,4 +9137,35 @@ public static String calculateMD5(InputStream in) throws NoSuchAlgorithmExceptio return sb.toString(); } + + /** + * Fully writes communication message to provided stream. + * + * @param msg Message. + * @param out Stream to write to. + * @param buf Byte buffer that will be passed to {@link MessageAdapter#writeTo(ByteBuffer)} method. + * @return Number of written bytes. + * @throws IOException In case of error. + */ + public static int writeMessageFully(MessageAdapter msg, OutputStream out, ByteBuffer buf) throws IOException { + assert msg != null; + assert out != null; + assert buf != null; + assert buf.hasArray(); + + boolean finished = false; + int cnt = 0; + + while (!finished) { + finished = msg.writeTo(buf); + + out.write(buf.array(), 0, buf.position()); + + cnt += buf.position(); + + buf.clear(); + } + + return cnt; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUuidCache.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUuidCache.java similarity index 92% rename from modules/core/src/main/java/org/apache/ignite/internal/util/GridUuidCache.java rename to modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUuidCache.java index bbcb7db32fa2e..045589c73a87d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUuidCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUuidCache.java @@ -23,7 +23,7 @@ /** * */ -public final class GridUuidCache { +public final class IgniteUuidCache { /** Maximum cache size. */ private static final int MAX = 1024; @@ -37,7 +37,7 @@ public final class GridUuidCache { * @param id Read UUID. * @return Cached UUID equivalent to the read one. */ - public static UUID onGridUuidRead(UUID id) { + public static UUID onIgniteUuidRead(UUID id) { UUID cached = cache.get(id); if (cached == null) { @@ -53,7 +53,7 @@ public static UUID onGridUuidRead(UUID id) { /** * Ensure singleton. */ - private GridUuidCache() { + private IgniteUuidCache() { // No-op. } } 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 deleted file mode 100644 index 95b49666dedf5..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageAdapter.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.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.internal.util.nio.*; -import org.apache.ignite.lang.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.nio.*; -import java.util.*; - -import static org.apache.ignite.events.EventType.*; - -/** - * Communication message adapter. - */ -public abstract class GridTcpCommunicationMessageAdapter implements Serializable, Cloneable { - /** */ - 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 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 Enum ENUM_NOT_READ = DummyEnum.DUMMY; - - /** */ - 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(); - - /** */ - protected final GridTcpCommunicationMessageState commState = new GridTcpCommunicationMessageState(); - - /** - * @param msgWriter Message writer. - * @param nodeId Node ID (provided only if versions are different). - */ - public void messageWriter(GridNioMessageWriter msgWriter, @Nullable UUID nodeId) { - assert msgWriter != null; - - commState.messageWriter(msgWriter, nodeId); - } - - /** - * @param msgReader Message reader. - * @param nodeId Node ID (provided only if versions are different). - */ - public void messageReader(GridNioMessageReader msgReader, @Nullable UUID nodeId) { - assert msgReader != null; - - commState.messageReader(msgReader, nodeId); - } - - /** - * @param buf Byte buffer. - * @return Whether message was fully written. - */ - public abstract boolean writeTo(ByteBuffer buf); - - /** - * @param buf Byte buffer. - * @return Whether message was fully read. - */ - public abstract boolean readFrom(ByteBuffer buf); - - /** - * @return Message type. - */ - public abstract byte directType(); - - /** {@inheritDoc} */ - @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException") - @Override public abstract GridTcpCommunicationMessageAdapter clone(); - - /** - * Clones all fields of the provided message to {@code this}. - * - * @param _msg Message to clone from. - */ - protected abstract void clone0(GridTcpCommunicationMessageAdapter _msg); - - /** - * @return {@code True} if should skip recovery for this message. - */ - public boolean skipRecovery() { - return false; - } - - /** - * @param arr Array. - * @return Array iterator. - */ - protected final Iterator arrayIterator(final Object[] arr) { - return new Iterator() { - private int idx; - - @Override public boolean hasNext() { - return idx < arr.length; - } - - @Override public Object next() { - if (!hasNext()) - throw new NoSuchElementException(); - - return arr[idx++]; - } - - @Override public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - - /** - * Dummy enum. - */ - private enum DummyEnum { - /** */ - DUMMY - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageFactory.java deleted file mode 100644 index 9ef1b10c8ea03..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageFactory.java +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.direct; - -import org.apache.ignite.internal.*; -import org.apache.ignite.internal.managers.checkpoint.*; -import org.apache.ignite.internal.managers.communication.*; -import org.apache.ignite.internal.managers.deployment.*; -import org.apache.ignite.internal.managers.eventstorage.*; -import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.processors.cache.distributed.*; -import org.apache.ignite.internal.processors.cache.distributed.dht.*; -import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*; -import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*; -import org.apache.ignite.internal.processors.cache.distributed.near.*; -import org.apache.ignite.internal.processors.cache.query.*; -import org.apache.ignite.internal.processors.clock.*; -import org.apache.ignite.internal.processors.continuous.*; -import org.apache.ignite.internal.processors.dataload.*; -import org.apache.ignite.internal.processors.rest.handlers.task.*; -import org.apache.ignite.internal.processors.streamer.*; -import org.apache.ignite.spi.collision.jobstealing.*; -import org.apache.ignite.spi.communication.tcp.*; -import org.jdk8.backport.*; - -import java.util.*; - -/** - * Communication message factory. - */ -public class GridTcpCommunicationMessageFactory { - /** Common message producers. */ - private static final GridTcpCommunicationMessageProducer[] COMMON = new GridTcpCommunicationMessageProducer[83]; - - /** - * Custom messages registry. Used for test purposes. - */ - private static final Map CUSTOM = new ConcurrentHashMap8<>(); - - /** */ - public static final int MAX_COMMON_TYPE = 82; - - static { - registerCommon(new GridTcpCommunicationMessageProducer() { - @Override public GridTcpCommunicationMessageAdapter create(byte type) { - switch (type) { - case 0: - return new GridJobCancelRequest(); - - case 2: - return new GridJobExecuteResponse(); - - case 3: - return new GridJobSiblingsRequest(); - - case 4: - return new GridJobSiblingsResponse(); - - case 5: - return new GridTaskCancelRequest(); - - case 6: - return new GridTaskSessionRequest(); - - case 7: - return new GridCheckpointRequest(); - - case 8: - return new GridIoMessage(); - - case 9: - return new GridIoUserMessage(); - - case 10: - return new GridDeploymentInfoBean(); - - case 11: - return new GridDeploymentRequest(); - - case 12: - return new GridDeploymentResponse(); - - case 13: - return new GridEventStorageMessage(); - - case 16: - return new GridCacheEvictionRequest(); - - case 17: - return new GridCacheEvictionResponse(); - - case 18: - return new GridCacheOptimisticCheckPreparedTxRequest(); - - case 19: - return new GridCacheOptimisticCheckPreparedTxResponse(); - - case 20: - return new GridCachePessimisticCheckCommittedTxRequest(); - - case 21: - return new GridCachePessimisticCheckCommittedTxResponse(); - - case 22: - return new GridDistributedLockRequest(); - - case 23: - return new GridDistributedLockResponse(); - - case 24: - return new GridDistributedTxFinishRequest(); - - case 25: - return new GridDistributedTxFinishResponse(); - - case 26: - return new GridDistributedTxPrepareRequest(); - - case 27: - return new GridDistributedTxPrepareResponse(); - - case 28: - return new GridDistributedUnlockRequest(); - - case 29: - return new GridDhtLockRequest(); - - case 30: - return new GridDhtLockResponse(); - - case 31: - return new GridDhtTxFinishRequest(); - - case 32: - return new GridDhtTxFinishResponse(); - - case 33: - return new GridDhtTxPrepareRequest(); - - case 34: - return new GridDhtTxPrepareResponse(); - - case 35: - return new GridDhtUnlockRequest(); - - case 36: - return new GridDhtAtomicDeferredUpdateResponse(); - - case 37: - return new GridDhtAtomicUpdateRequest(); - - case 38: - return new GridDhtAtomicUpdateResponse(); - - case 39: - return new GridNearAtomicUpdateRequest(); - - case 40: - return new GridNearAtomicUpdateResponse(); - - case 41: - return new GridDhtForceKeysRequest(); - - case 42: - return new GridDhtForceKeysResponse(); - - case 43: - return new GridDhtPartitionDemandMessage(); - - case 44: - return new GridDhtPartitionSupplyMessage(); - - case 45: - return new GridDhtPartitionsFullMessage(); - - case 46: - return new GridDhtPartitionsSingleMessage(); - - case 47: - return new GridDhtPartitionsSingleRequest(); - - case 48: - return new GridNearGetRequest(); - - case 49: - return new GridNearGetResponse(); - - case 50: - return new GridNearLockRequest(); - - case 51: - return new GridNearLockResponse(); - - case 52: - return new GridNearTxFinishRequest(); - - case 53: - return new GridNearTxFinishResponse(); - - case 54: - return new GridNearTxPrepareRequest(); - - case 55: - return new GridNearTxPrepareResponse(); - - case 56: - return new GridNearUnlockRequest(); - - case 57: - return new GridCacheQueryRequest(); - - case 58: - return new GridCacheQueryResponse(); - - case 59: - return new GridClockDeltaSnapshotMessage(); - - case 60: - return new GridContinuousMessage(); - - case 61: - return new GridDataLoadRequest(); - - case 62: - return new GridDataLoadResponse(); - - // 65-72 are GGFS messages (see GridGgfsOpProcessor). - - case 73: - return new GridTaskResultRequest(); - - case 74: - return new GridTaskResultResponse(); - - // TODO: Register from streamer processor. - case 75: - return new GridStreamerCancelRequest(); - - case 76: - return new GridStreamerExecutionRequest(); - - case 77: - return new GridStreamerResponse(); - - case 78: - return new JobStealingRequest(); - - case 79: - return new GridDhtAffinityAssignmentRequest(); - - case 80: - return new GridDhtAffinityAssignmentResponse(); - - case 81: - return new GridJobExecuteRequest(); - - case 82: - return new GridCacheTtlUpdateRequest(); - - default: - assert false : "Invalid message type."; - - return null; - } - } - }, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, /* 65-72 - GGFS messages. */ 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82); - } - - /** - * @param type Message type. - * @return New message. - */ - public static GridTcpCommunicationMessageAdapter create(byte type) { - if (type == TcpCommunicationSpi.NODE_ID_MSG_TYPE) - return new TcpCommunicationSpi.NodeIdMessage(); - else if (type == TcpCommunicationSpi.RECOVERY_LAST_ID_MSG_TYPE) - return new TcpCommunicationSpi.RecoveryLastReceivedMessage(); - else if (type == TcpCommunicationSpi.HANDSHAKE_MSG_TYPE) - return new TcpCommunicationSpi.HandshakeMessage(); - else - return create0(type); - } - - /** - * @param type Message type. - * @return New message. - */ - private static GridTcpCommunicationMessageAdapter create0(byte type) { - if (type >= 0 && type < COMMON.length) { - GridTcpCommunicationMessageProducer producer = COMMON[type]; - - if (producer != null) - return producer.create(type); - else - throw new IllegalStateException("Common message type producer is not registered: " + type); - } - else { - GridTcpCommunicationMessageProducer c = CUSTOM.get(type); - - if (c != null) - return c.create(type); - else - throw new IllegalStateException("Custom message type producer is not registered: " + type); - } - } - - /** - * Register message producer for common message type. - * - * @param producer Producer. - * @param types Types applicable for this producer. - */ - public static void registerCommon(GridTcpCommunicationMessageProducer producer, int... types) { - for (int type : types) { - assert type >= 0 && type < COMMON.length : "Commmon type being registered is out of common messages " + - "array length: " + type; - - COMMON[type] = producer; - } - } - - /** - * Registers factory for custom message. Used for test purposes. - * - * @param producer Message producer. - * @param type Message type. - */ - public static void registerCustom(GridTcpCommunicationMessageProducer producer, byte type) { - assert producer != null; - - CUSTOM.put(type, producer); - } - - /** - * @return Common message producers. - */ - public static GridTcpCommunicationMessageProducer[] commonProducers() { - return COMMON; - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageProducer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageProducer.java deleted file mode 100644 index a856603108a90..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageProducer.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.direct; - -/** - * Message producer. Each component have to register it's own message producer. - */ -public interface GridTcpCommunicationMessageProducer { - /** - * Create message. - * - * @param type Message type. - * @return Communication message. - */ - public GridTcpCommunicationMessageAdapter create(byte type); -} 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 deleted file mode 100644 index de9ac4a6eb8d8..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageState.java +++ /dev/null @@ -1,1599 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.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.internal.util.nio.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.lang.*; -import org.jetbrains.annotations.*; -import sun.misc.*; -import sun.nio.ch.*; - -import java.nio.*; -import java.util.*; - -import static org.apache.ignite.internal.util.direct.GridTcpCommunicationMessageAdapter.*; - -/** - * Communication message state. - */ -@SuppressWarnings("PublicField") -public class GridTcpCommunicationMessageState { - /** */ - private static final Unsafe UNSAFE = GridUnsafe.unsafe(); - - /** */ - private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class); - - /** */ - private static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class); - - /** */ - private static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class); - - /** */ - private static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class); - - /** */ - private static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class); - - /** */ - private static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class); - - /** */ - private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class); - - /** */ - private static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class); - - /** */ - private static final byte[] BYTE_ARR_EMPTY = new byte[0]; - - /** */ - private static final short[] SHORT_ARR_EMPTY = new short[0]; - - /** */ - private static final int[] INT_ARR_EMPTY = new int[0]; - - /** */ - private static final long[] LONG_ARR_EMPTY = new long[0]; - - /** */ - private static final float[] FLOAT_ARR_EMPTY = new float[0]; - - /** */ - private static final double[] DOUBLE_ARR_EMPTY = new double[0]; - - /** */ - private static final char[] CHAR_ARR_EMPTY = new char[0]; - - /** */ - private static final boolean[] BOOLEAN_ARR_EMPTY = new boolean[0]; - - /** */ - private static final byte[] EMPTY_UUID_BYTES = new byte[16]; - - /** */ - private static final ArrayCreator BYTE_ARR_CREATOR = new ArrayCreator() { - @Override public byte[] create(int len) { - switch (len) { - case -1: - return BYTE_ARR_NOT_READ; - - case 0: - return BYTE_ARR_EMPTY; - - default: - return new byte[len]; - } - } - }; - - /** */ - private static final ArrayCreator SHORT_ARR_CREATOR = new ArrayCreator() { - @Override public short[] create(int len) { - switch (len) { - case -1: - return SHORT_ARR_NOT_READ; - - case 0: - return SHORT_ARR_EMPTY; - - default: - return new short[len]; - } - } - }; - - /** */ - private static final ArrayCreator INT_ARR_CREATOR = new ArrayCreator() { - @Override public int[] create(int len) { - switch (len) { - case -1: - return INT_ARR_NOT_READ; - - case 0: - return INT_ARR_EMPTY; - - default: - return new int[len]; - } - } - }; - - /** */ - private static final ArrayCreator LONG_ARR_CREATOR = new ArrayCreator() { - @Override public long[] create(int len) { - switch (len) { - case -1: - return LONG_ARR_NOT_READ; - - case 0: - return LONG_ARR_EMPTY; - - default: - return new long[len]; - } - } - }; - - /** */ - private static final ArrayCreator FLOAT_ARR_CREATOR = new ArrayCreator() { - @Override public float[] create(int len) { - switch (len) { - case -1: - return FLOAT_ARR_NOT_READ; - - case 0: - return FLOAT_ARR_EMPTY; - - default: - return new float[len]; - } - } - }; - - /** */ - private static final ArrayCreator DOUBLE_ARR_CREATOR = new ArrayCreator() { - @Override public double[] create(int len) { - switch (len) { - case -1: - return DOUBLE_ARR_NOT_READ; - - case 0: - return DOUBLE_ARR_EMPTY; - - default: - return new double[len]; - } - } - }; - - /** */ - private static final ArrayCreator CHAR_ARR_CREATOR = new ArrayCreator() { - @Override public char[] create(int len) { - switch (len) { - case -1: - return CHAR_ARR_NOT_READ; - - case 0: - return CHAR_ARR_EMPTY; - - default: - return new char[len]; - } - } - }; - - /** */ - private static final ArrayCreator BOOLEAN_ARR_CREATOR = new ArrayCreator() { - @Override public boolean[] create(int len) { - switch (len) { - case -1: - return BOOLEAN_ARR_NOT_READ; - - case 0: - return BOOLEAN_ARR_EMPTY; - - default: - return new boolean[len]; - } - } - }; - - /** */ - private GridNioMessageWriter msgWriter; - - /** */ - private GridNioMessageReader msgReader; - - /** */ - private UUID nodeId; - - /** */ - private ByteBuffer buf; - - /** */ - private byte[] heapArr; - - /** */ - private long baseOff; - - /** */ - private boolean arrHdrDone; - - /** */ - private int arrOff; - - /** */ - private Object tmpArr; - - /** */ - private int tmpArrOff; - - /** */ - private int tmpArrBytes; - - /** */ - private boolean msgNotNull; - - /** */ - private boolean msgNotNullDone; - - /** */ - private boolean msgTypeDone; - - /** */ - private GridTcpCommunicationMessageAdapter msg; - - /** */ - public int idx; - - /** */ - public boolean typeWritten; - - /** */ - public Iterator it; - - /** */ - public Object cur = NULL; - - /** */ - public boolean keyDone; - - /** */ - public int readSize = -1; - - /** */ - public int readItems; - - /** - * @param msgWriter Message writer. - * @param nodeId Node ID (provided only if versions are different). - */ - public void messageWriter(GridNioMessageWriter msgWriter, @Nullable UUID nodeId) { - assert msgWriter != null; - - this.msgWriter = msgWriter; - this.nodeId = nodeId; - } - - /** - * @param msgReader Message reader. - * @param nodeId Node ID (provided only if versions are different). - */ - public void messageReader(GridNioMessageReader msgReader, @Nullable UUID nodeId) { - assert msgReader != null; - - this.msgReader = msgReader; - this.nodeId = nodeId; - } - - /** - * @param buf Buffer. - */ - public final void setBuffer(ByteBuffer buf) { - assert buf != null; - - if (this.buf != buf) { - this.buf = buf; - - heapArr = buf.isDirect() ? null : buf.array(); - baseOff = buf.isDirect() ? ((DirectBuffer)buf).address() : BYTE_ARR_OFF; - } - } - - /** - * @param b Byte value. - * @return Whether value was written. - */ - public final boolean putByte(byte b) { - assert buf != null; - - if (!buf.hasRemaining()) - return false; - - int pos = buf.position(); - - UNSAFE.putByte(heapArr, baseOff + pos, b); - - buf.position(pos + 1); - - return true; - } - - /** - * @return Byte value. - */ - public final byte getByte() { - assert buf != null; - assert buf.hasRemaining(); - - int pos = buf.position(); - - buf.position(pos + 1); - - return UNSAFE.getByte(heapArr, baseOff + pos); - } - - /** - * @param s Short value. - * @return Whether value was written. - */ - public final boolean putShort(short s) { - assert buf != null; - - if (buf.remaining() < 2) - return false; - - int pos = buf.position(); - - UNSAFE.putShort(heapArr, baseOff + pos, s); - - buf.position(pos + 2); - - return true; - } - - /** - * @return Short value. - */ - public final short getShort() { - assert buf != null; - assert buf.remaining() >= 2; - - int pos = buf.position(); - - buf.position(pos + 2); - - return UNSAFE.getShort(heapArr, baseOff + pos); - } - - /** - * @param i Integer value. - * @return Whether value was written. - */ - public final boolean putInt(int i) { - assert buf != null; - - if (buf.remaining() < 4) - return false; - - int pos = buf.position(); - - UNSAFE.putInt(heapArr, baseOff + pos, i); - - buf.position(pos + 4); - - return true; - } - - /** - * @return Integer value. - */ - public final int getInt() { - assert buf != null; - assert buf.remaining() >= 4; - - int pos = buf.position(); - - buf.position(pos + 4); - - return UNSAFE.getInt(heapArr, baseOff + pos); - } - - /** - * @param l Long value. - * @return Whether value was written. - */ - public final boolean putLong(long l) { - assert buf != null; - - if (buf.remaining() < 8) - return false; - - int pos = buf.position(); - - UNSAFE.putLong(heapArr, baseOff + pos, l); - - buf.position(pos + 8); - - return true; - } - - /** - * @return Long value. - */ - public final long getLong() { - assert buf != null; - assert buf.remaining() >= 8; - - int pos = buf.position(); - - buf.position(pos + 8); - - return UNSAFE.getLong(heapArr, baseOff + pos); - } - - /** - * @param f Float value. - * @return Whether value was written. - */ - public final boolean putFloat(float f) { - assert buf != null; - - if (buf.remaining() < 4) - return false; - - int pos = buf.position(); - - UNSAFE.putFloat(heapArr, baseOff + pos, f); - - buf.position(pos + 4); - - return true; - } - - /** - * @return Float value. - */ - public final float getFloat() { - assert buf != null; - assert buf.remaining() >= 4; - - int pos = buf.position(); - - buf.position(pos + 4); - - return UNSAFE.getFloat(heapArr, baseOff + pos); - } - - /** - * @param d Double value. - * @return Whether value was written. - */ - public final boolean putDouble(double d) { - assert buf != null; - - if (buf.remaining() < 8) - return false; - - int pos = buf.position(); - - UNSAFE.putDouble(heapArr, baseOff + pos, d); - - buf.position(pos + 8); - - return true; - } - - /** - * @return Double value. - */ - public final double getDouble() { - assert buf != null; - assert buf.remaining() >= 8; - - int pos = buf.position(); - - buf.position(pos + 8); - - return UNSAFE.getDouble(heapArr, baseOff + pos); - } - - /** - * @param c Char value. - * @return Whether value was written. - */ - public final boolean putChar(char c) { - assert buf != null; - - if (buf.remaining() < 2) - return false; - - int pos = buf.position(); - - UNSAFE.putChar(heapArr, baseOff + pos, c); - - buf.position(pos + 2); - - return true; - } - - /** - * @return Char value. - */ - public final char getChar() { - assert buf != null; - assert buf.remaining() >= 2; - - int pos = buf.position(); - - buf.position(pos + 2); - - return UNSAFE.getChar(heapArr, baseOff + pos); - } - - /** - * @param b Boolean value. - * @return Whether value was written. - */ - public final boolean putBoolean(boolean b) { - assert buf != null; - - if (buf.remaining() < 1) - return false; - - int pos = buf.position(); - - UNSAFE.putBoolean(heapArr, baseOff + pos, b); - - buf.position(pos + 1); - - return true; - } - - /** - * @return Boolean value. - */ - public final boolean getBoolean() { - assert buf != null; - assert buf.hasRemaining(); - - int pos = buf.position(); - - buf.position(pos + 1); - - return UNSAFE.getBoolean(heapArr, baseOff + pos); - } - - /** - * @param arr Byte array. - * @return Whether array was fully written. - */ - public final boolean putByteArray(@Nullable byte[] arr) { - assert buf != null; - - int len = arr != null ? arr.length : 0; - - return putArray(arr, BYTE_ARR_OFF, len, len); - } - - /** - * @return Byte array or special - * {@link GridTcpCommunicationMessageAdapter#BYTE_ARR_NOT_READ} - * value if it was not fully read. - */ - public final byte[] getByteArray() { - assert buf != null; - - return getArray(BYTE_ARR_CREATOR, 0, BYTE_ARR_OFF); - } - - /** - * @param arr Short array. - * @return Whether array was fully written. - */ - public final boolean putShortArray(short[] arr) { - assert buf != null; - - int len = arr != null ? arr.length : 0; - - return putArray(arr, SHORT_ARR_OFF, len, len << 1); - } - - /** - * @return Short array or special - * {@link GridTcpCommunicationMessageAdapter#SHORT_ARR_NOT_READ} - * value if it was not fully read. - */ - public final short[] getShortArray() { - assert buf != null; - - return getArray(SHORT_ARR_CREATOR, 1, SHORT_ARR_OFF); - } - - /** - * @param arr Integer array. - * @return Whether array was fully written. - */ - public final boolean putIntArray(int[] arr) { - assert buf != null; - - int len = arr != null ? arr.length : 0; - - return putArray(arr, INT_ARR_OFF, len, len << 2); - } - - /** - * @return Integer array or special - * {@link GridTcpCommunicationMessageAdapter#INT_ARR_NOT_READ} - * value if it was not fully read. - */ - public final int[] getIntArray() { - assert buf != null; - - return getArray(INT_ARR_CREATOR, 2, INT_ARR_OFF); - } - - /** - * @param arr Long array. - * @return Whether array was fully written. - */ - public final boolean putLongArray(long[] arr) { - assert buf != null; - - int len = arr != null ? arr.length : 0; - - return putArray(arr, LONG_ARR_OFF, len, len << 3); - } - - /** - * @return Long array or special - * {@link GridTcpCommunicationMessageAdapter#LONG_ARR_NOT_READ} - * value if it was not fully read. - */ - public final long[] getLongArray() { - assert buf != null; - - return getArray(LONG_ARR_CREATOR, 3, LONG_ARR_OFF); - } - - /** - * @param arr Float array. - * @return Whether array was fully written. - */ - public final boolean putFloatArray(float[] arr) { - assert buf != null; - - int len = arr != null ? arr.length : 0; - - return putArray(arr, FLOAT_ARR_OFF, len, len << 2); - } - - /** - * @return Float array or special - * {@link GridTcpCommunicationMessageAdapter#FLOAT_ARR_NOT_READ} - * value if it was not fully read. - */ - public final float[] getFloatArray() { - assert buf != null; - - return getArray(FLOAT_ARR_CREATOR, 2, FLOAT_ARR_OFF); - } - - /** - * @param arr Double array. - * @return Whether array was fully written. - */ - public final boolean putDoubleArray(double[] arr) { - assert buf != null; - - int len = arr != null ? arr.length : 0; - - return putArray(arr, DOUBLE_ARR_OFF, len, len << 3); - } - - /** - * @return Double array or special - * {@link GridTcpCommunicationMessageAdapter#DOUBLE_ARR_NOT_READ} - * value if it was not fully read. - */ - public final double[] getDoubleArray() { - assert buf != null; - - return getArray(DOUBLE_ARR_CREATOR, 3, DOUBLE_ARR_OFF); - } - - /** - * @param arr Char array. - * @return Whether array was fully written. - */ - public final boolean putCharArray(char[] arr) { - assert buf != null; - - int len = arr != null ? arr.length : 0; - - return putArray(arr, CHAR_ARR_OFF, len, len << 1); - } - - /** - * @return Char array or special - * {@link GridTcpCommunicationMessageAdapter#CHAR_ARR_NOT_READ} - * value if it was not fully read. - */ - public final char[] getCharArray() { - assert buf != null; - - return getArray(CHAR_ARR_CREATOR, 1, CHAR_ARR_OFF); - } - - /** - * @param arr Boolean array. - * @return Whether array was fully written. - */ - public final boolean putBooleanArray(boolean[] arr) { - assert buf != null; - - int len = arr != null ? arr.length : 0; - - return putArray(arr, BOOLEAN_ARR_OFF, len, len); - } - - /** - * @return Boolean array or special - * {@link GridTcpCommunicationMessageAdapter#BOOLEAN_ARR_NOT_READ} - * value if it was not fully read. - */ - public final boolean[] getBooleanArray() { - assert buf != null; - - return getArray(BOOLEAN_ARR_CREATOR, 0, BOOLEAN_ARR_OFF); - } - - /** - * @param uuid {@link UUID}. - * @return Whether value was fully written. - */ - public final boolean putUuid(@Nullable UUID uuid) { - byte[] arr = null; - - if (uuid != null) { - arr = new byte[16]; - - UNSAFE.putLong(arr, BYTE_ARR_OFF, uuid.getMostSignificantBits()); - UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, uuid.getLeastSignificantBits()); - } - - return putByteArray(arr); - } - - /** - * @return {@link UUID} or special - * {@link GridTcpCommunicationMessageAdapter#UUID_NOT_READ} - * value if it was not fully read. - */ - public final UUID getUuid() { - byte[] arr = getByteArray(); - - if (arr == BYTE_ARR_NOT_READ) - return UUID_NOT_READ; - else if (arr == null) - return null; - else { - long most = UNSAFE.getLong(arr, BYTE_ARR_OFF); - long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8); - - return new UUID(most, least); - } - } - - /** - * @param uuid {@link org.apache.ignite.lang.IgniteUuid}. - * @return Whether value was fully written. - */ - public final boolean putGridUuid(@Nullable IgniteUuid uuid) { - byte[] arr = null; - - if (uuid != null) { - arr = new byte[24]; - - UNSAFE.putLong(arr, BYTE_ARR_OFF, uuid.globalId().getMostSignificantBits()); - UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, uuid.globalId().getLeastSignificantBits()); - UNSAFE.putLong(arr, BYTE_ARR_OFF + 16, uuid.localId()); - } - - return putByteArray(arr); - } - - /** - * @return {@link org.apache.ignite.lang.IgniteUuid} or special - * {@link GridTcpCommunicationMessageAdapter#GRID_UUID_NOT_READ} - * value if it was not fully read. - */ - public final IgniteUuid getGridUuid() { - byte[] arr = getByteArray(); - - if (arr == BYTE_ARR_NOT_READ) - return GRID_UUID_NOT_READ; - else if (arr == null) - return null; - else { - long most = UNSAFE.getLong(arr, BYTE_ARR_OFF); - long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8); - long loc = UNSAFE.getLong(arr, BYTE_ARR_OFF + 16); - - return new IgniteUuid(new UUID(most, least), loc); - } - } - - /** - * @param ver {@link GridClockDeltaVersion}. - * @return Whether value was fully written. - */ - public final boolean putClockDeltaVersion(@Nullable GridClockDeltaVersion ver) { - byte[] arr = null; - - if (ver != null) { - arr = new byte[16]; - - UNSAFE.putLong(arr, BYTE_ARR_OFF, ver.version()); - UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, ver.topologyVersion()); - } - - return putByteArray(arr); - } - - /** - * @return {@link GridClockDeltaVersion} or special - * {@link GridTcpCommunicationMessageAdapter#CLOCK_DELTA_VER_NOT_READ} - * value if it was not fully read. - */ - public final GridClockDeltaVersion getClockDeltaVersion() { - byte[] arr = getByteArray(); - - if (arr == BYTE_ARR_NOT_READ) - return CLOCK_DELTA_VER_NOT_READ; - else if (arr == null) - return null; - else { - long ver = UNSAFE.getLong(arr, BYTE_ARR_OFF); - long topVer = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8); - - return new GridClockDeltaVersion(ver, topVer); - } - } - - /** - * @param list {@link GridByteArrayList}. - * @return Whether value was fully written. - */ - public final boolean putByteArrayList(@Nullable GridByteArrayList list) { - byte[] arr = list != null ? list.internalArray() : null; - int size = list != null ? list.size() : 0; - - return putArray(arr, BYTE_ARR_OFF, size, size); - } - - /** - * @return {@link GridByteArrayList} or special - * {@link GridTcpCommunicationMessageAdapter#BYTE_ARR_LIST_NOT_READ} - * value if it was not fully read. - */ - @SuppressWarnings("IfMayBeConditional") - public final GridByteArrayList getByteArrayList() { - byte[] arr = getByteArray(); - - if (arr == BYTE_ARR_NOT_READ) - return BYTE_ARR_LIST_NOT_READ; - else if (arr == null) - return null; - else - return new GridByteArrayList(arr); - } - - /** - * @param list {@link GridLongList}. - * @return Whether value was fully written. - */ - public final boolean putLongList(@Nullable GridLongList list) { - long[] arr = list != null ? list.internalArray() : null; - int size = list != null ? list.size() : 0; - - return putArray(arr, LONG_ARR_OFF, size, size << 3); - } - - /** - * @return {@link GridLongList} or special - * {@link GridTcpCommunicationMessageAdapter#LONG_LIST_NOT_READ} - * value if it was not fully read. - */ - @SuppressWarnings("IfMayBeConditional") - public final GridLongList getLongList() { - long[] arr = getLongArray(); - - if (arr == LONG_ARR_NOT_READ) - return LONG_LIST_NOT_READ; - else if (arr == null) - return null; - else - return new GridLongList(arr); - } - - /** - * @param ver {@link org.apache.ignite.internal.processors.cache.version.GridCacheVersion}. - * @return Whether value was fully written. - */ - public final boolean putCacheVersion(@Nullable GridCacheVersion ver) { - byte[] arr = null; - - if (ver != null) { - arr = new byte[24]; - - UNSAFE.putInt(arr, BYTE_ARR_OFF, ver.topologyVersion()); - UNSAFE.putInt(arr, BYTE_ARR_OFF + 4, ver.nodeOrderAndDrIdRaw()); - UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, ver.globalTime()); - UNSAFE.putLong(arr, BYTE_ARR_OFF + 16, ver.order()); - } - - return putByteArray(arr); - } - - /** - * @return {@link GridCacheVersion} or special - * {@link GridTcpCommunicationMessageAdapter#CACHE_VER_NOT_READ} - * value if it was not fully read. - */ - public final GridCacheVersion getCacheVersion() { - byte[] arr = getByteArray(); - - if (arr == BYTE_ARR_NOT_READ) - return CACHE_VER_NOT_READ; - else if (arr == null) - return null; - else { - int topVerDrId = UNSAFE.getInt(arr, BYTE_ARR_OFF); - int nodeOrder = UNSAFE.getInt(arr, BYTE_ARR_OFF + 4); - long globalTime = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8); - long order = UNSAFE.getLong(arr, BYTE_ARR_OFF + 16); - - return new GridCacheVersion(topVerDrId, nodeOrder, globalTime, order); - } - } - - /** - * @param id {@link GridDhtPartitionExchangeId}. - * @return Whether value was fully written. - */ - public final boolean putDhtPartitionExchangeId(@Nullable GridDhtPartitionExchangeId id) { - byte[] arr = null; - - if (id != null) { - arr = new byte[28]; - - UNSAFE.putLong(arr, BYTE_ARR_OFF, id.nodeId().getMostSignificantBits()); - UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, id.nodeId().getLeastSignificantBits()); - UNSAFE.putInt(arr, BYTE_ARR_OFF + 16, id.event()); - UNSAFE.putLong(arr, BYTE_ARR_OFF + 20, id.topologyVersion()); - } - - return putByteArray(arr); - } - - /** - * @return {@link GridDhtPartitionExchangeId} or special - * {@link GridTcpCommunicationMessageAdapter#DHT_PART_EXCHANGE_ID_NOT_READ} - * value if it was not fully read. - */ - public final GridDhtPartitionExchangeId getDhtPartitionExchangeId() { - byte[] arr = getByteArray(); - - if (arr == BYTE_ARR_NOT_READ) - return DHT_PART_EXCHANGE_ID_NOT_READ; - else if (arr == null) - return null; - else { - long most = UNSAFE.getLong(arr, BYTE_ARR_OFF); - long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8); - int evt = UNSAFE.getInt(arr, BYTE_ARR_OFF + 16); - long topVer = UNSAFE.getLong(arr, BYTE_ARR_OFF + 20); - - return new GridDhtPartitionExchangeId(new UUID(most, least), evt, topVer); - } - } - - /** - * @param bytes {@link GridCacheValueBytes}. - * @return Whether value was fully written. - */ - public final boolean putValueBytes(@Nullable GridCacheValueBytes bytes) { - byte[] arr = null; - - if (bytes != null) { - if (bytes.get() != null) { - int len = bytes.get().length; - - arr = new byte[len + 2]; - - UNSAFE.putBoolean(arr, BYTE_ARR_OFF, true); - UNSAFE.copyMemory(bytes.get(), BYTE_ARR_OFF, arr, BYTE_ARR_OFF + 1, len); - UNSAFE.putBoolean(arr, BYTE_ARR_OFF + 1 + len, bytes.isPlain()); - } - else { - arr = new byte[1]; - - UNSAFE.putBoolean(arr, BYTE_ARR_OFF, false); - } - } - - return putByteArray(arr); - } - - /** - * @return {@link GridCacheValueBytes} or special - * {@link GridTcpCommunicationMessageAdapter#VAL_BYTES_NOT_READ} - * value if it was not fully read. - */ - public final GridCacheValueBytes getValueBytes() { - byte[] arr = getByteArray(); - - if (arr == BYTE_ARR_NOT_READ) - return VAL_BYTES_NOT_READ; - else if (arr == null) - return null; - else { - boolean notNull = UNSAFE.getBoolean(arr, BYTE_ARR_OFF); - - if (notNull) { - int len = arr.length - 2; - - assert len >= 0 : len; - - byte[] bytesArr = new byte[len]; - - UNSAFE.copyMemory(arr, BYTE_ARR_OFF + 1, bytesArr, BYTE_ARR_OFF, len); - - boolean isPlain = UNSAFE.getBoolean(arr, BYTE_ARR_OFF + 1 + len); - - return new GridCacheValueBytes(bytesArr, isPlain); - } - else - return new GridCacheValueBytes(); - } - } - - /** - * @param str {@link String}. - * @return Whether value was fully written. - */ - public final boolean putString(@Nullable String str) { - return putByteArray(str != null ? str.getBytes() : null); - } - - /** - * @return {@link String} or special {@link GridTcpCommunicationMessageAdapter#STR_NOT_READ} - * value if it was not fully read. - */ - @SuppressWarnings("IfMayBeConditional") - public final String getString() { - byte[] arr = getByteArray(); - - if (arr == BYTE_ARR_NOT_READ) - return STR_NOT_READ; - else if (arr == null) - return null; - else - return new String(arr); - } - - /** - * @param bits {@link BitSet}. - * @return Whether value was fully written. - */ - public final boolean putBitSet(@Nullable BitSet bits) { - return putLongArray(bits != null ? bits.toLongArray() : null); - } - - /** - * @return {@link BitSet} or special {@link GridTcpCommunicationMessageAdapter#BIT_SET_NOT_READ} - * value if it was not fully read. - */ - @SuppressWarnings("IfMayBeConditional") - public final BitSet getBitSet() { - long[] arr = getLongArray(); - - if (arr == LONG_ARR_NOT_READ) - return BIT_SET_NOT_READ; - else if (arr == null) - return null; - else - return BitSet.valueOf(arr); - } - - /** - * @param e Enum. - * @return Whether value was fully written. - */ - public final boolean putEnum(@Nullable Enum e) { - return putByte(e != null ? (byte)e.ordinal() : -1); - } - - /** - * @param msg {@link GridTcpCommunicationMessageAdapter}. - * @return Whether value was fully written. - */ - public final boolean putMessage(@Nullable GridTcpCommunicationMessageAdapter msg) { - assert buf != null; - - if (!msgNotNullDone) { - if (!putBoolean(msg != null)) - return false; - - msgNotNullDone = true; - } - - if (msg != null) { - if (!msgWriter.write(nodeId, msg, buf)) - return false; - - msgNotNullDone = false; - } - - return true; - } - - /** - * @return {@link GridTcpCommunicationMessageAdapter} or special - * {@link GridTcpCommunicationMessageAdapter#MSG_NOT_READ} - * value if it was not fully read. - */ - public final GridTcpCommunicationMessageAdapter getMessage() { - assert buf != null; - - if (!msgNotNullDone) { - if (!buf.hasRemaining()) - return MSG_NOT_READ; - - msgNotNull = getBoolean(); - - msgNotNullDone = true; - } - - if (msgNotNull) { - if (!msgTypeDone) { - if (!buf.hasRemaining()) - return MSG_NOT_READ; - - GridTcpMessageFactory factory = msgReader.messageFactory(); - - byte type = getByte(); - - msg = factory != null ? factory.create(type) : GridTcpCommunicationMessageFactory.create(type); - - msgTypeDone = true; - } - - if (msgReader.read(nodeId, msg, buf)) { - GridTcpCommunicationMessageAdapter msg0 = msg; - - msgNotNullDone = false; - msgTypeDone = false; - msg = null; - - return msg0; - } - else - return MSG_NOT_READ; - } - else - return null; - } - - /** - * @param arr Array. - * @param off Offset. - * @param len Length. - * @param bytes Length in bytes. - * @return Whether array was fully written - */ - private boolean putArray(@Nullable Object arr, long off, int len, int bytes) { - assert off > 0; - assert len >= 0; - assert bytes >= 0; - assert bytes >= arrOff; - - if (!buf.hasRemaining()) - return false; - - int pos = buf.position(); - - if (arr != null) { - assert arr.getClass().isArray() && arr.getClass().getComponentType().isPrimitive(); - - if (!arrHdrDone) { - if (buf.remaining() < 5) - return false; - - UNSAFE.putBoolean(heapArr, baseOff + pos++, true); - UNSAFE.putInt(heapArr, baseOff + pos, len); - - pos += 4; - - buf.position(pos); - - arrHdrDone = true; - } - - if (!buf.hasRemaining()) - return false; - - int left = bytes - arrOff; - int remaining = buf.remaining(); - - if (left <= remaining) { - UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, left); - - pos += left; - - buf.position(pos); - - arrHdrDone = false; - arrOff = 0; - } - else { - UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, remaining); - - pos += remaining; - - buf.position(pos); - - arrOff += remaining; - - return false; - } - } - else { - UNSAFE.putBoolean(heapArr, baseOff + pos++, false); - - buf.position(pos); - } - - return true; - } - - /** - * @param creator Array creator. - * @param lenShift Array length shift size. - * @param off Base offset. - * @return Array or special value if it was not fully read. - */ - private T getArray(ArrayCreator creator, int lenShift, long off) { - assert creator != null; - assert lenShift >= 0; - - if (!arrHdrDone) { - if (!buf.hasRemaining()) - return creator.create(-1); - - if (!getBoolean()) - return null; - - arrHdrDone = true; - } - - if (tmpArr == null) { - if (buf.remaining() < 4) - return creator.create(-1); - - int len = getInt(); - - if (len == 0) { - arrHdrDone = false; - - return creator.create(0); - } - - tmpArr = creator.create(len); - tmpArrBytes = len << lenShift; - } - - int toRead = tmpArrBytes - tmpArrOff; - int remaining = buf.remaining(); - int pos = buf.position(); - - if (remaining < toRead) { - UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, remaining); - - buf.position(pos + remaining); - - tmpArrOff += remaining; - - return creator.create(-1); - } - else { - UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, toRead); - - buf.position(pos + toRead); - - T arr = (T)tmpArr; - - arrHdrDone = false; - tmpArr = null; - tmpArrBytes = 0; - tmpArrOff = 0; - - return arr; - } - } - - /** - * @param i Integer value. - * @return Whether value was written. - */ - public final boolean putIntClient(int i) { - assert buf != null; - - if (buf.remaining() < 4) - return false; - - putByte((byte)(0xFF & (i >>> 24))); - putByte((byte)(0xFF & (i >>> 16))); - putByte((byte)(0xFF & (i >>> 8))); - putByte((byte)(0xFF & i)); - - return true; - } - - /** - * @return Integer value. - */ - public final int getIntClient() { - assert buf != null; - assert buf.remaining() >= 4; - - int val = 0; - - val |= (0xFF & getByte()) << 24; - val |= (0xFF & getByte()) << 16; - val |= (0xFF & getByte()) << 8; - val |= (0xFF & getByte()); - - return val; - } - - /** - * @param val Long value. - * @return Whether value was written. - */ - public final boolean putLongClient(long val) { - assert buf != null; - - if (buf.remaining() < 8) - return false; - - putByte((byte)(val >>> 56)); - putByte((byte)(0xFFL & (val >>> 48))); - putByte((byte)(0xFFL & (val >>> 40))); - putByte((byte)(0xFFL & (val >>> 32))); - putByte((byte)(0xFFL & (val >>> 24))); - putByte((byte)(0xFFL & (val >>> 16))); - putByte((byte)(0xFFL & (val >>> 8))); - putByte((byte) (0xFFL & val)); - - return true; - } - - /** - * @return Long value. - */ - public final long getLongClient() { - assert buf != null; - assert buf.remaining() >= 8; - - long x = 0; - - x |= (0xFFL & getByte()) << 56; - x |= (0xFFL & getByte()) << 48; - x |= (0xFFL & getByte()) << 40; - x |= (0xFFL & getByte()) << 32; - x |= (0xFFL & getByte()) << 24; - x |= (0xFFL & getByte()) << 16; - x |= (0xFFL & getByte()) << 8; - x |= (0xFFL & getByte()); - - return x; - } - - /** - * @param uuid {@link UUID}. - * @return Whether value was fully written. - */ - public final boolean putUuidClient(@Nullable UUID uuid) { - byte[] arr = uuid != null ? U.uuidToBytes(uuid) : EMPTY_UUID_BYTES; - - return putByteArrayClient(arr); - } - - /** - * @param arr Byte array. - * @return Whether array was fully written. - */ - public final boolean putByteArrayClient(byte[] arr) { - assert buf != null; - assert arr != null; - - return putArrayClient(arr, BYTE_ARR_OFF, arr.length, arr.length); - } - - /** - * @param src Buffer. - * @return Whether array was fully written - */ - public boolean putByteBufferClient(ByteBuffer src) { - assert src != null; - assert src.hasArray(); - - return putArrayClient(src.array(), BYTE_ARR_OFF + src.position(), src.remaining(), src.remaining()); - } - - /** - * @param arr Array. - * @param off Offset. - * @param len Length. - * @param bytes Length in bytes. - * @return Whether array was fully written - */ - private boolean putArrayClient(Object arr, long off, int len, int bytes) { - assert off > 0; - assert len >= 0; - assert bytes >= 0; - assert bytes >= arrOff; - assert arr != null; - - if (!buf.hasRemaining()) - return false; - - int pos = buf.position(); - - assert arr.getClass().isArray() && arr.getClass().getComponentType().isPrimitive(); - - if (!arrHdrDone) - arrHdrDone = true; - - if (!buf.hasRemaining()) - return false; - - int left = bytes - arrOff; - int remaining = buf.remaining(); - - if (left <= remaining) { - UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, left); - - pos += left; - - buf.position(pos); - - arrHdrDone = false; - arrOff = 0; - } - else { - UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, remaining); - - pos += remaining; - - buf.position(pos); - - arrOff += remaining; - - return false; - } - - return true; - } - - /** - * @param len Array length. - * @return Byte array or special {@link GridTcpCommunicationMessageAdapter#BYTE_ARR_NOT_READ} - * value if it was not fully read. - */ - public final byte[] getByteArrayClient(int len) { - assert buf != null; - - return getArrayClient(BYTE_ARR_CREATOR, BYTE_ARR_OFF, len); - } - - /** - * @return {@link UUID} or special - * {@link GridTcpCommunicationMessageAdapter#UUID_NOT_READ} - * value if it was not fully read. - */ - public final UUID getUuidClient() { - byte[] arr = getByteArrayClient(16); - - assert arr != null; - - return arr == BYTE_ARR_NOT_READ ? UUID_NOT_READ : U.bytesToUuid(arr, 0); - } - - /** - * @param creator Array creator. - * @param off Base offset. - * @param len Length. - * @return Array or special value if it was not fully read. - */ - private T getArrayClient(ArrayCreator creator, long off, int len) { - assert creator != null; - - if (tmpArr == null) { - tmpArr = creator.create(len); - tmpArrBytes = len; - } - - int toRead = tmpArrBytes - tmpArrOff; - int remaining = buf.remaining(); - int pos = buf.position(); - - if (remaining < toRead) { - UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, remaining); - - buf.position(pos + remaining); - - tmpArrOff += remaining; - - return creator.create(-1); - } - else { - UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, toRead); - - buf.position(pos + toRead); - - T arr = (T)tmpArr; - - arrHdrDone = false; - tmpArr = null; - tmpArrBytes = 0; - tmpArrOff = 0; - - return arr; - } - } - - /** - * Array creator. - */ - private static interface ArrayCreator { - /** - * @param len Array length or {@code -1} if array was not fully read. - * @return New array. - */ - public T create(int len); - } - - /** - * Dummy enum. - */ - private enum DummyEnum { - /** */ - DUMMY - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java index 5097db7fcbcc3..388c38fa99f97 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java @@ -18,8 +18,9 @@ package org.apache.ignite.internal.util.ipc; import org.apache.ignite.*; -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 java.io.*; import java.nio.*; @@ -53,24 +54,23 @@ public class IpcToNioAdapter { private final GridNioMetricsListener metricsLsnr; /** */ - private final GridNioMessageWriter msgWriter; + private final MessageFormatter formatter; /** * @param metricsLsnr Metrics listener. * @param log Log. * @param endp Endpoint. - * @param msgWriter Message writer. * @param lsnr Listener. + * @param formatter Message formatter. * @param filters Filters. */ public IpcToNioAdapter(GridNioMetricsListener metricsLsnr, IgniteLogger log, IpcEndpoint endp, - GridNioMessageWriter msgWriter, GridNioServerListener lsnr, GridNioFilter... filters) { + GridNioServerListener lsnr, MessageFormatter formatter, GridNioFilter... filters) { assert metricsLsnr != null; - assert msgWriter != null; this.metricsLsnr = metricsLsnr; this.endp = endp; - this.msgWriter = msgWriter; + this.formatter = formatter; chain = new GridNioFilterChain<>(log, lsnr, new HeadFilter(), filters); ses = new GridNioSessionImpl(chain, null, null, true); @@ -148,14 +148,13 @@ else if (read < 0) { * @param msg Buffer to send. * @return Send result. */ - private GridNioFuture send(GridTcpCommunicationMessageAdapter msg) { + private GridNioFuture send(MessageAdapter msg) { assert writeBuf.hasArray(); try { - // This method is called only on handshake, - // so we don't need to provide node ID for - // rolling updates support. - int cnt = msgWriter.writeFully(null, msg, endp.outputStream(), writeBuf); + msg.setWriter(formatter.writer()); + + int cnt = U.writeMessageFully(msg, endp.outputStream(), writeBuf); metricsLsnr.onBytesSent(cnt); } @@ -196,7 +195,7 @@ protected HeadFilter() { @Override public GridNioFuture onSessionWrite(GridNioSession ses, Object msg) { assert ses == IpcToNioAdapter.this.ses; - return send((GridTcpCommunicationMessageAdapter)msg); + return send((MessageAdapter)msg); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java index 96ad8aa8320ee..5b99f5800fb90 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java @@ -3064,6 +3064,65 @@ public static GridIterator flat(@Nullable final Iterable Iterator flatIterators(@Nullable final Iterable> c) { + return isEmpty(c) ? GridFunc.emptyIterator() : new GridIteratorAdapter() { + /** */ + private Iterator> a = c.iterator(); + + /** */ + private Iterator b; + + /** */ + private boolean moved = true; + + /** */ + private boolean more; + + @Override public boolean hasNextX() { + if (!moved) + return more; + + moved = false; + + if (b != null && b.hasNext()) + return more = true; + + while (a.hasNext()) { + b = a.next(); + + if (b.hasNext()) + return more = true; + } + + return more = false; + } + + @Override public T nextX() { + if (hasNext()) { + moved = true; + + return b.next(); + } + + throw new NoSuchElementException(); + } + + @Override public void removeX() { + assert b != null; + + b.remove(); + } + }; + } + /** * Flattens given set objects into a single collection. Unrolls {@link Collection}, * {@link Iterable} and {@code Object[]} objects. @@ -4286,6 +4345,96 @@ public static GridIterator iterator(final Iterable c, }; } + /** + * @param c Input iterator. + * @param trans Transforming closure to convert from T1 to T2. + * @param readOnly If {@code true}, then resulting iterator will not allow modifications + * to the underlying collection. + * @param p Optional filtering predicates. + * @return Iterator from given iterator and optional filtering predicate. + */ + public static Iterator iterator(final Iterator c, + final IgniteClosure trans, + final boolean readOnly, + @Nullable final IgnitePredicate... p) + { + A.notNull(c, "c", trans, "trans"); + + if (isAlwaysFalse(p)) + return F.emptyIterator(); + + return new GridIteratorAdapter() { + /** */ + private T1 elem; + + /** */ + private boolean moved = true; + + /** */ + private boolean more; + + /** */ + private Iterator iter = c; + + @Override public boolean hasNextX() { + if (isEmpty(p)) + return iter.hasNext(); + else { + if (!moved) + return more; + else { + more = false; + + while (iter.hasNext()) { + elem = iter.next(); + + boolean isAll = true; + + for (IgnitePredicate r : p) + if (r != null && !r.apply(elem)) { + isAll = false; + + break; + } + + if (isAll) { + more = true; + moved = false; + + return true; + } + } + + elem = null; // Give to GC. + + return false; + } + } + } + + @Nullable @Override public T2 nextX() { + if (isEmpty(p)) + return trans.apply(iter.next()); + else { + if (hasNext()) { + moved = true; + + return trans.apply(elem); + } + else + throw new NoSuchElementException(); + } + } + + @Override public void removeX() { + if (readOnly) + throw new UnsupportedOperationException("Cannot modify read-only iterator."); + + iter.remove(); + } + }; + } + /** * Gets predicate that always returns {@code true}. This method returns * constant predicate. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java index e8ddb7d0d997d..6084e09f78c3a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java @@ -18,8 +18,8 @@ package org.apache.ignite.internal.util.nio; import org.apache.ignite.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -97,7 +97,7 @@ public interface GridCommunicationClient { * @throws IgniteCheckedException If failed. * @return {@code True} if should try to resend message. */ - boolean sendMessage(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg) throws IgniteCheckedException; + boolean sendMessage(@Nullable UUID nodeId, MessageAdapter msg) throws IgniteCheckedException; /** * @param timeout Timeout. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridDirectParser.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridDirectParser.java index 23d1f7932e898..3b00bd90f7752 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridDirectParser.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridDirectParser.java @@ -18,13 +18,11 @@ package org.apache.ignite.internal.util.nio; import org.apache.ignite.*; -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.spi.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; import java.nio.*; -import java.util.*; /** * Parser for direct messages. @@ -33,31 +31,21 @@ public class GridDirectParser implements GridNioParser { /** Message metadata key. */ private static final int MSG_META_KEY = GridNioSessionMetaKey.nextUniqueKey(); - /** Message reader. */ - private final GridNioMessageReader msgReader; - - /** */ - private IgniteSpiAdapter spi; - /** */ - private GridTcpMessageFactory msgFactory; + private final MessageFactory msgFactory; /** - * @param msgReader Message reader. - * @param spi Spi. + * @param msgFactory Message factory. */ - public GridDirectParser(GridNioMessageReader msgReader, IgniteSpiAdapter spi) { - this.msgReader = msgReader; - this.spi = spi; + public GridDirectParser(MessageFactory msgFactory) { + assert msgFactory != null; + + this.msgFactory = msgFactory; } /** {@inheritDoc} */ @Nullable @Override public Object decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException { - if (msgFactory == null) - msgFactory = spi.getSpiContext().messageFactory(); - - GridTcpCommunicationMessageAdapter msg = ses.removeMeta(MSG_META_KEY); - UUID nodeId = ses.meta(GridNioServer.DIFF_VER_NODE_ID_META_KEY); + MessageAdapter msg = ses.removeMeta(MSG_META_KEY); if (msg == null && buf.hasRemaining()) msg = msgFactory.create(buf.get()); @@ -65,7 +53,7 @@ public GridDirectParser(GridNioMessageReader msgReader, IgniteSpiAdapter spi) { boolean finished = false; if (buf.hasRemaining()) - finished = msgReader.read(nodeId, msg, buf); + finished = msg.readFrom(buf); if (finished) return msg; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioMessageReader.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioMessageReader.java index c4c3bb4da2b4e..9ae5bbd481672 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioMessageReader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioMessageReader.java @@ -17,7 +17,7 @@ package org.apache.ignite.internal.util.nio; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.nio.*; @@ -33,10 +33,10 @@ public interface GridNioMessageReader { * @param buf Buffer. * @return Whether message was fully read. */ - public boolean read(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, ByteBuffer buf); + public boolean read(@Nullable UUID nodeId, MessageAdapter msg, ByteBuffer buf); /** * @return Optional message factory. */ - @Nullable public GridTcpMessageFactory messageFactory(); + @Nullable public MessageFactory messageFactory(); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioMessageWriter.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioMessageWriter.java index 38ce18c81eac3..e517b3c95f0db 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioMessageWriter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioMessageWriter.java @@ -17,7 +17,7 @@ package org.apache.ignite.internal.util.nio; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -34,7 +34,7 @@ public interface GridNioMessageWriter { * @param buf Buffer. * @return Whether message was fully written. */ - public boolean write(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, ByteBuffer buf); + public boolean write(@Nullable UUID nodeId, MessageAdapter msg, ByteBuffer buf); /** * @param nodeId Node ID. @@ -44,6 +44,6 @@ public interface GridNioMessageWriter { * @return Number of bytes written. * @throws IOException In case of error. */ - public int writeFully(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, OutputStream out, + public int writeFully(@Nullable UUID nodeId, MessageAdapter msg, OutputStream out, ByteBuffer buf) throws IOException; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java index 7bf52e1979e85..ffa345d311187 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java @@ -21,13 +21,13 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.nio.ssl.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.worker.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.thread.*; import org.jdk8.backport.*; import org.jetbrains.annotations.*; @@ -67,12 +67,9 @@ public class GridNioServer { /** Buffer metadata key. */ private static final int BUF_META_KEY = GridNioSessionMetaKey.nextUniqueKey(); - /** SSL sysmtem data buffer metadata key. */ + /** SSL system data buffer metadata key. */ private static final int BUF_SSL_SYSTEM_META_KEY = GridNioSessionMetaKey.nextUniqueKey(); - /** Node ID meta key (set only if versions are different). */ - public static final int DIFF_VER_NODE_ID_META_KEY = GridNioSessionMetaKey.nextUniqueKey(); - /** Accept worker thread. */ @GridToStringExclude private final IgniteThread acceptThread; @@ -134,15 +131,16 @@ public class GridNioServer { /** Metrics listener. */ private final GridNioMetricsListener metricsLsnr; - /** Message writer. */ - private final GridNioMessageWriter msgWriter; - /** Sessions. */ private final GridConcurrentHashSet sessions = new GridConcurrentHashSet<>(); /** */ private GridNioSslFilter sslFilter; + /** */ + @GridToStringExclude + private MessageFormatter formatter; + /** Static initializer ensures single-threaded execution of workaround. */ static { // This is a workaround for JDK bug (NPE in Selector.open()). @@ -170,7 +168,7 @@ public class GridNioServer { * @param directMode Whether direct mode is used. * @param daemon Daemon flag to create threads. * @param metricsLsnr Metrics listener. - * @param msgWriter Message writer. + * @param formatter Message formatter. * @param filters Filters for this server. * @throws IgniteCheckedException If failed. */ @@ -190,7 +188,7 @@ private GridNioServer( boolean directMode, boolean daemon, GridNioMetricsListener metricsLsnr, - GridNioMessageWriter msgWriter, + MessageFormatter formatter, GridNioFilter... filters ) throws IgniteCheckedException { A.notNull(addr, "addr"); @@ -255,7 +253,7 @@ private GridNioServer( this.directMode = directMode; this.metricsLsnr = metricsLsnr; - this.msgWriter = msgWriter; + this.formatter = formatter; } /** @@ -348,7 +346,7 @@ GridNioFuture send(GridNioSession ses, ByteBuffer msg) { * @param msg Message. * @return Future for operation. */ - GridNioFuture send(GridNioSession ses, GridTcpCommunicationMessageAdapter msg) { + GridNioFuture send(GridNioSession ses, MessageAdapter msg) { assert ses instanceof GridSelectorNioSessionImpl; GridSelectorNioSessionImpl impl = (GridSelectorNioSessionImpl)ses; @@ -387,7 +385,7 @@ else if (msgCnt == 1) * @param msg Message. * @return Future. */ - public GridNioFuture sendSystem(GridNioSession ses, GridTcpCommunicationMessageAdapter msg) { + public GridNioFuture sendSystem(GridNioSession ses, MessageAdapter msg) { return sendSystem(ses, msg, null); } @@ -400,7 +398,7 @@ public GridNioFuture sendSystem(GridNioSession ses, GridTcpCommunicationMessa * @return Future. */ public GridNioFuture sendSystem(GridNioSession ses, - GridTcpCommunicationMessageAdapter msg, + MessageAdapter msg, @Nullable IgniteInClosure> lsnr) { assert ses instanceof GridSelectorNioSessionImpl; @@ -863,7 +861,6 @@ private void processWriteSsl(SelectionKey key) throws IOException { ByteBuffer buf = ses.writeBuffer(); NioOperationFuture req = ses.removeMeta(NIO_OPERATION.ordinal()); - UUID nodeId = ses.meta(DIFF_VER_NODE_ID_META_KEY); List> doneFuts = null; @@ -878,16 +875,15 @@ private void processWriteSsl(SelectionKey key) throws IOException { } } - GridTcpCommunicationMessageAdapter msg; + MessageAdapter msg; boolean finished = false; if (req != null) { msg = req.directMessage(); assert msg != null; - assert msgWriter != null; - finished = msgWriter.write(nodeId, msg, buf); + finished = msg.writeTo(buf); } // Fill up as many messages as possible to write buffer. @@ -905,9 +901,8 @@ private void processWriteSsl(SelectionKey key) throws IOException { msg = req.directMessage(); assert msg != null; - assert msgWriter != null; - finished = msgWriter.write(nodeId, msg, buf); + finished = msg.writeTo(buf); } buf.flip(); @@ -1003,7 +998,6 @@ private void processWrite0(SelectionKey key) throws IOException { GridSelectorNioSessionImpl ses = (GridSelectorNioSessionImpl)key.attachment(); ByteBuffer buf = ses.writeBuffer(); NioOperationFuture req = ses.removeMeta(NIO_OPERATION.ordinal()); - UUID nodeId = ses.meta(DIFF_VER_NODE_ID_META_KEY); List> doneFuts = null; @@ -1018,16 +1012,17 @@ private void processWrite0(SelectionKey key) throws IOException { } } - GridTcpCommunicationMessageAdapter msg; + MessageAdapter msg; boolean finished = false; if (req != null) { msg = req.directMessage(); assert msg != null; - assert msgWriter != null; - finished = msgWriter.write(nodeId, msg, buf); + msg.setWriter(formatter.writer()); + + finished = msg.writeTo(buf); } // Fill up as many messages as possible to write buffer. @@ -1045,9 +1040,10 @@ private void processWrite0(SelectionKey key) throws IOException { msg = req.directMessage(); assert msg != null; - assert msgWriter != null; - finished = msgWriter.write(nodeId, msg, buf); + msg.setWriter(formatter.writer()); + + finished = msg.writeTo(buf); } buf.flip(); @@ -1759,7 +1755,7 @@ private static class NioOperationFuture extends GridNioFutureImpl { private ByteBuffer msg; /** Direct message. */ - private GridTcpCommunicationMessageAdapter commMsg; + private MessageAdapter commMsg; /** */ private boolean accepted; @@ -1835,7 +1831,7 @@ private static class NioOperationFuture extends GridNioFutureImpl { * @param commMsg Direct message. */ NioOperationFuture(GridSelectorNioSessionImpl ses, NioOperation op, - GridTcpCommunicationMessageAdapter commMsg) { + MessageAdapter commMsg) { assert ses != null; assert op != null; assert op != NioOperation.REGISTER; @@ -1863,7 +1859,7 @@ private ByteBuffer message() { /** * @return Direct message. */ - private GridTcpCommunicationMessageAdapter directMessage() { + private MessageAdapter directMessage() { return commMsg; } @@ -1974,7 +1970,7 @@ protected HeadFilter() { return null; } else - return send(ses, (GridTcpCommunicationMessageAdapter)msg); + return send(ses, (MessageAdapter)msg); } else return send(ses, (ByteBuffer)msg); @@ -2061,9 +2057,6 @@ public static class Builder { /** Metrics listener. */ private GridNioMetricsListener metricsLsnr; - /** Message writer. */ - private GridNioMessageWriter msgWriter; - /** NIO filters. */ private GridNioFilter[] filters; @@ -2076,6 +2069,9 @@ public static class Builder { /** Daemon flag. */ private boolean daemon; + /** Message formatter. */ + private MessageFormatter formatter; + /** * Finishes building the instance. * @@ -2099,7 +2095,7 @@ public GridNioServer build() throws IgniteCheckedException { directMode, daemon, metricsLsnr, - msgWriter, + formatter, filters != null ? Arrays.copyOf(filters, filters.length) : EMPTY_FILTERS ); @@ -2253,16 +2249,6 @@ public Builder metricsListener(GridNioMetricsListener metricsLsnr) { return this; } - /** - * @param msgWriter Message writer. - * @return This for chaining. - */ - public Builder messageWriter(GridNioMessageWriter msgWriter) { - this.msgWriter = msgWriter; - - return this; - } - /** * @param filters NIO filters. * @return This for chaining. @@ -2302,5 +2288,15 @@ public Builder daemon(boolean daemon) { return this; } + + /** + * @param formatter Message formatter. + * @return This for chaining. + */ + public Builder messageFormatter(MessageFormatter formatter) { + this.formatter = formatter; + + return this; + } } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java index 2d908aea2248b..2add3256d9fac 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java @@ -18,10 +18,10 @@ package org.apache.ignite.internal.util.nio; import org.apache.ignite.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.ipc.shmem.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -39,37 +39,35 @@ public class GridShmemCommunicationClient extends GridAbstractCommunicationClien private final ByteBuffer writeBuf; /** */ - private final GridNioMessageWriter msgWriter; + private final MessageFormatter formatter; /** * @param metricsLsnr Metrics listener. * @param port Shared memory IPC server port. * @param connTimeout Connection timeout. * @param log Logger. - * @param msgWriter Message writer. + * @param formatter Message formatter. * @throws IgniteCheckedException If failed. */ - public GridShmemCommunicationClient(GridNioMetricsListener metricsLsnr, int port, long connTimeout, IgniteLogger log, - GridNioMessageWriter msgWriter) - throws IgniteCheckedException { + public GridShmemCommunicationClient(GridNioMetricsListener metricsLsnr, int port, long connTimeout, + IgniteLogger log, MessageFormatter formatter) throws IgniteCheckedException { super(metricsLsnr); assert metricsLsnr != null; - assert msgWriter != null; assert port > 0 && port < 0xffff; assert connTimeout >= 0; shmem = new IpcSharedMemoryClientEndpoint(port, (int)connTimeout, log); - this.msgWriter = msgWriter; - writeBuf = ByteBuffer.allocate(8 << 10); writeBuf.order(ByteOrder.nativeOrder()); + + this.formatter = formatter; } /** {@inheritDoc} */ - @Override public synchronized void doHandshake(IgniteInClosure2X handshakeC) + @Override public synchronized void doHandshake(IgniteInClosure2X handshakeC) throws IgniteCheckedException { handshakeC.applyx(shmem.inputStream(), shmem.outputStream()); } @@ -110,7 +108,7 @@ public GridShmemCommunicationClient(GridNioMetricsListener metricsLsnr, int port } /** {@inheritDoc} */ - @Override public synchronized boolean sendMessage(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg) + @Override public synchronized boolean sendMessage(@Nullable UUID nodeId, MessageAdapter msg) throws IgniteCheckedException { if (closed()) throw new IgniteCheckedException("Communication client was closed: " + this); @@ -118,7 +116,9 @@ public GridShmemCommunicationClient(GridNioMetricsListener metricsLsnr, int port assert writeBuf.hasArray(); try { - int cnt = msgWriter.writeFully(nodeId, msg, shmem.outputStream(), writeBuf); + msg.setWriter(formatter.writer()); + + int cnt = U.writeMessageFully(msg, shmem.outputStream(), writeBuf); metricsLsnr.onBytesSent(cnt); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java index 87230c298f371..fd2aeb9a45a11 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java @@ -18,9 +18,9 @@ package org.apache.ignite.internal.util.nio; import org.apache.ignite.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -46,14 +46,13 @@ public class GridTcpCommunicationClient extends GridAbstractCommunicationClient private final double bufSizeRatio; /** */ - private final GridNioMessageWriter msgWriter; + private final ByteBuffer writeBuf; /** */ - private final ByteBuffer writeBuf; + private final MessageFormatter formatter; /** * @param metricsLsnr Metrics listener. - * @param msgWriter Message writer. * @param addr Address. * @param locHost Local address. * @param connTimeout Connect timeout. @@ -63,11 +62,11 @@ public class GridTcpCommunicationClient extends GridAbstractCommunicationClient * @param bufSize Buffer size (or {@code 0} to disable buffer). * @param minBufferedMsgCnt Minimum buffered message count. * @param bufSizeRatio Communication buffer size ratio. + * @param formatter Message formatter. * @throws IgniteCheckedException If failed. */ public GridTcpCommunicationClient( GridNioMetricsListener metricsLsnr, - GridNioMessageWriter msgWriter, InetSocketAddress addr, InetAddress locHost, long connTimeout, @@ -76,12 +75,12 @@ public GridTcpCommunicationClient( int sockSndBuf, int bufSize, int minBufferedMsgCnt, - double bufSizeRatio + double bufSizeRatio, + MessageFormatter formatter ) throws IgniteCheckedException { super(metricsLsnr); assert metricsLsnr != null; - assert msgWriter != null; assert addr != null; assert locHost != null; assert connTimeout >= 0; @@ -92,9 +91,9 @@ public GridTcpCommunicationClient( A.ensure(bufSizeRatio > 0 && bufSizeRatio < 1, "Value of bufSizeRatio property must be between 0 and 1 (exclusive)."); - this.msgWriter = msgWriter; this.minBufferedMsgCnt = minBufferedMsgCnt; this.bufSizeRatio = bufSizeRatio; + this.formatter = formatter; writeBuf = ByteBuffer.allocate(8 << 10); @@ -190,7 +189,7 @@ public GridTcpCommunicationClient( } /** {@inheritDoc} */ - @Override public boolean sendMessage(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg) + @Override public boolean sendMessage(@Nullable UUID nodeId, MessageAdapter msg) throws IgniteCheckedException { if (closed()) throw new IgniteCheckedException("Client was closed: " + this); @@ -198,7 +197,9 @@ public GridTcpCommunicationClient( assert writeBuf.hasArray(); try { - int cnt = msgWriter.writeFully(nodeId, msg, out, writeBuf); + msg.setWriter(formatter.writer()); + + int cnt = U.writeMessageFully(msg, out, writeBuf); metricsLsnr.onBytesSent(cnt); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java index 2b71d61aa3ea8..46d0646b44958 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java @@ -18,9 +18,9 @@ package org.apache.ignite.internal.util.nio; import org.apache.ignite.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.jetbrains.annotations.*; import java.io.*; @@ -103,7 +103,7 @@ public GridNioSession session() { } /** {@inheritDoc} */ - @Override public boolean sendMessage(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg) + @Override public boolean sendMessage(@Nullable UUID nodeId, MessageAdapter msg) throws IgniteCheckedException { // Node ID is never provided in asynchronous send mode. assert nodeId == null; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapMap.java index 9f4e4b4faebe9..d10aa226ccba7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapMap.java @@ -124,6 +124,13 @@ public interface GridOffHeapMap { */ public void insert(int hash, byte[] keyBytes, byte[] valBytes); + /** + * Gets number of elements in the map. + * + * @return Number of elements in the map. + */ + public long totalSize(); + /** * Gets number of elements in the map. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java index 06a83a7d6f977..49850abc1e2da 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java @@ -22,6 +22,8 @@ import org.apache.ignite.lang.*; import org.jetbrains.annotations.*; +import java.util.*; + /** * Off-heap map. */ @@ -141,6 +143,15 @@ public interface GridOffHeapPartitionedMap { */ public long size(); + + /** + * Gets number of elements in the map. + * + * @param parts Partitions. + * @return Number of elements in the map. + */ + public long size(Set parts); + /** * Gets total available memory size. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java index 229f4f28f61da..dc742c710bbd8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java @@ -329,10 +329,20 @@ private void init(long initCap, int size) { } /** {@inheritDoc} */ - @Override public long size() { + @Override public long totalSize() { return totalCnt.sum(); } + /** {@inheritDoc} */ + @Override public long size() { + long size = 0; + + for (int i = 0; i < segs.length; i++) + size += segs[i].count(); + + return size; + } + /** {@inheritDoc} */ @Override public long memorySize() { return mem.totalSize(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java index 343c08bd317ff..4d4ba61a6015a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java @@ -208,6 +208,16 @@ private GridOffHeapMap mapFor(int p) { return totalCnt.sum(); } + /** {@inheritDoc} */ + @Override public long size(Set parts) { + int cnt = 0; + + for (Integer part : parts) + cnt += mapFor(part).size(); + + return cnt; + } + /** {@inheritDoc} */ @Override public long memorySize() { return mem.totalSize(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/portable/PortableRawReaderEx.java b/modules/core/src/main/java/org/apache/ignite/internal/util/portable/PortableRawReaderEx.java deleted file mode 100644 index 1cb5749dce18e..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/portable/PortableRawReaderEx.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.portable; - -import org.apache.ignite.portables.*; -import org.jetbrains.annotations.*; - -/** - * Extended reader interface. - */ -public interface PortableRawReaderEx extends PortableRawReader { - /** - * @return Object. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - @Nullable public Object readObjectDetached() throws PortableException; -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/portable/PortableRawWriterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/util/portable/PortableRawWriterEx.java deleted file mode 100644 index df7c83ce8627f..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/portable/PortableRawWriterEx.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.portable; - -import org.apache.ignite.internal.processors.portable.*; -import org.apache.ignite.portables.*; -import org.jetbrains.annotations.*; - -/** - * Extended writer interface. - */ -public interface PortableRawWriterEx extends PortableRawWriter, AutoCloseable { - /** - * @param obj Object to write. - * @throws org.apache.ignite.portables.PortableException In case of error. - */ - public void writeObjectDetached(@Nullable Object obj) throws PortableException; - - /** - * @return Output stream. - */ - public GridPortableOutputStream out(); - - /** - * Cleans resources. - */ - @Override public void close(); -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadata.java deleted file mode 100644 index 74a39971301fc..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadata.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.visor.portable; - -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.io.*; -import java.util.*; - -/** - * Portable object metadata to show in Visor. - */ -public class VisorPortableMetadata implements Serializable { - /** */ - private static final long serialVersionUID = 0L; - - /** Type name */ - private String typeName; - - /** Type Id */ - private Integer typeId; - - /** Filed list */ - private Collection fields; - - /** Type name */ - public String typeName() { - return typeName; - } - - public void typeName(String typeName) { - this.typeName = typeName; - } - - /** Type Id */ - public Integer typeId() { - return typeId; - } - - public void typeId(Integer typeId) { - this.typeId = typeId; - } - - /** Fields list */ - public Collection fields() { - return fields; - } - - public void fields(Collection fields) { - this.fields = fields; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(VisorPortableMetadata.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadataCollectorTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadataCollectorTask.java deleted file mode 100644 index 8fc967a43d1d1..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadataCollectorTask.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.visor.portable; - -import org.apache.ignite.*; -import org.apache.ignite.internal.processors.task.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.internal.visor.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.portables.*; - -import java.util.*; - -/** - * Task that collects portables metadata. - */ -@GridInternal -public class VisorPortableMetadataCollectorTask extends VisorOneNodeTask>> { - /** */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override protected VisorPortableCollectMetadataJob job(Long lastUpdate) { - return new VisorPortableCollectMetadataJob(lastUpdate, debug); - } - - /** Job that collect portables metadata on node. */ - private static class VisorPortableCollectMetadataJob extends VisorJob>> { - /** */ - private static final long serialVersionUID = 0L; - - /** - * Create job with given argument. - * - * @param lastUpdate Time data was collected last time. - * @param debug Debug flag. - */ - private VisorPortableCollectMetadataJob(Long lastUpdate, boolean debug) { - super(lastUpdate, debug); - } - - /** {@inheritDoc} */ - @Override protected IgniteBiTuple> run(Long lastUpdate) { - final IgnitePortables p = g.portables(); - - final Collection data = new ArrayList<>(p.metadata().size()); - - for(PortableMetadata metadata: p.metadata()) { - final VisorPortableMetadata type = new VisorPortableMetadata(); - - type.typeName(metadata.typeName()); - - type.typeId(p.typeId(metadata.typeName())); - - final Collection fields = new ArrayList<>(metadata.fields().size()); - - for (String fieldName: metadata.fields()) { - final VisorPortableMetadataField field = new VisorPortableMetadataField(); - - field.fieldName(fieldName); - field.fieldTypeName(metadata.fieldTypeName(fieldName)); - - fields.add(field); - } - - type.fields(fields); - - data.add(type); - } - - return new IgniteBiTuple<>(0L, data); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(VisorPortableCollectMetadataJob.class, this); - } - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadataField.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadataField.java deleted file mode 100644 index d5cbac47ebeb7..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/portable/VisorPortableMetadataField.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.visor.portable; - -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.io.*; - -/** - * Portable object metadata field information. - */ -public class VisorPortableMetadataField implements Serializable { - /** */ - private static final long serialVersionUID = 0L; - - /** Field name. */ - private String fieldName; - - /** Field type name. */ - private String fieldTypeName; - - /** Field id. */ - private Integer fieldId; - - /** Field name. */ - public String fieldName() { - return fieldName; - } - - public void fieldName(String fieldName) { - this.fieldName = fieldName; - } - - /** Field type name. */ - public String fieldTypeName() { - return fieldTypeName; - } - - public void fieldTypeName(String fieldTypeName) { - this.fieldTypeName = fieldTypeName; - } - - /** Field id. */ - public Integer fieldId() { - return fieldId; - } - - public void fieldId(Integer fieldId) { - this.fieldId = fieldId; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(VisorPortableMetadataField.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/optimized-classnames.properties b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/optimized-classnames.properties index bb8aecf210d37..e6ece603d8883 100644 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/optimized-classnames.properties +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/optimized-classnames.properties @@ -96,8 +96,8 @@ org.apache.ignite.cache.query.QueryAffinityPredicate org.apache.ignite.cache.query.QueryContinuousPredicate org.apache.ignite.cache.query.QuerySqlPredicate org.apache.ignite.cache.query.QueryTextPredicate -org.apache.ignite.cache.store.jdbc.JdbcCacheStore$EntryMapping$1 -org.apache.ignite.cache.store.jdbc.JdbcCacheStore$EntryMapping$2 +org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore$EntryMapping$1 +org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore$EntryMapping$2 org.apache.ignite.cache.store.jdbc.dialect.BasicJdbcDialect$1 org.apache.ignite.cache.store.jdbc.dialect.BasicJdbcDialect$2 org.apache.ignite.cache.store.jdbc.dialect.BasicJdbcDialect$3 @@ -152,42 +152,41 @@ org.apache.ignite.compute.gridify.aop.GridifyArgumentAdapter org.apache.ignite.compute.gridify.aop.GridifyDefaultRangeTask org.apache.ignite.compute.gridify.aop.GridifyDefaultTask org.apache.ignite.compute.gridify.aop.spring.GridifySpringPointcut$GridifySpringPointcutType -org.apache.ignite.configuration.IgniteDeploymentMode -org.apache.ignite.configuration.TransactionsConfiguration -org.apache.ignite.datastructures.DataStructureRemovedException -org.apache.ignite.events.IgniteAuthenticationEvent -org.apache.ignite.events.IgniteAuthorizationEvent -org.apache.ignite.events.IgniteCacheEvent -org.apache.ignite.events.IgniteCachePreloadingEvent -org.apache.ignite.events.IgniteCacheQueryExecutedEvent -org.apache.ignite.events.IgniteCacheQueryReadEvent -org.apache.ignite.events.IgniteCheckpointEvent -org.apache.ignite.events.IgniteDeploymentEvent -org.apache.ignite.events.IgniteDiscoveryEvent -org.apache.ignite.events.IgniteEventAdapter +org.apache.ignite.configuration.DeploymentMode +org.apache.ignite.configuration.TransactionConfiguration +org.apache.ignite.events.AuthenticationEvent +org.apache.ignite.events.AuthorizationEvent +org.apache.ignite.events.CacheEvent +org.apache.ignite.events.CachePreloadingEvent +org.apache.ignite.events.CacheQueryExecutedEvent +org.apache.ignite.events.CacheQueryReadEvent +org.apache.ignite.events.CheckpointEvent +org.apache.ignite.events.DeploymentEvent +org.apache.ignite.events.DiscoveryEvent +org.apache.ignite.events.EventAdapter org.apache.ignite.events.IgniteFsEvent -org.apache.ignite.events.IgniteJobEvent -org.apache.ignite.events.IgniteLicenseEvent -org.apache.ignite.events.IgniteSecureSessionEvent -org.apache.ignite.events.IgniteSwapSpaceEvent -org.apache.ignite.events.IgniteTaskEvent -org.apache.ignite.fs.IgniteFsConcurrentModificationException -org.apache.ignite.fs.IgniteFsCorruptedFileException -org.apache.ignite.fs.IgniteFsException -org.apache.ignite.fs.IgniteFsFileNotFoundException -org.apache.ignite.fs.IgniteFsGroupDataBlocksKeyMapper -org.apache.ignite.fs.IgniteFsInvalidHdfsVersionException -org.apache.ignite.fs.IgniteFsInvalidPathException -org.apache.ignite.fs.IgniteFsMode -org.apache.ignite.fs.IgniteFsOutOfSpaceException -org.apache.ignite.fs.IgniteFsParentNotDirectoryException -org.apache.ignite.fs.IgniteFsPath -org.apache.ignite.fs.IgniteFsPathAlreadyExistsException -org.apache.ignite.fs.IgniteFsPathSummary -org.apache.ignite.fs.mapreduce.records.IgniteFsByteDelimiterRecordResolver -org.apache.ignite.fs.mapreduce.records.IgniteFsFixedLengthRecordResolver -org.apache.ignite.fs.mapreduce.records.IgniteFsNewLineRecordResolver -org.apache.ignite.fs.mapreduce.records.IgniteFsStringDelimiterRecordResolver +org.apache.ignite.events.JobEvent +org.apache.ignite.events.LicenseEvent +org.apache.ignite.events.SecureSessionEvent +org.apache.ignite.events.SwapSpaceEvent +org.apache.ignite.events.TaskEvent +org.apache.ignite.ignitefs.IgniteFsConcurrentModificationException +org.apache.ignite.ignitefs.IgniteFsCorruptedFileException +org.apache.ignite.ignitefs.IgniteFsException +org.apache.ignite.ignitefs.IgniteFsFileNotFoundException +org.apache.ignite.ignitefs.IgniteFsGroupDataBlocksKeyMapper +org.apache.ignite.ignitefs.IgniteFsInvalidHdfsVersionException +org.apache.ignite.ignitefs.IgniteFsInvalidPathException +org.apache.ignite.ignitefs.IgniteFsMode +org.apache.ignite.ignitefs.IgniteFsOutOfSpaceException +org.apache.ignite.ignitefs.IgniteFsParentNotDirectoryException +org.apache.ignite.ignitefs.IgniteFsPath +org.apache.ignite.ignitefs.IgniteFsPathAlreadyExistsException +org.apache.ignite.ignitefs.IgniteFsPathSummary +org.apache.ignite.ignitefs.mapreduce.records.IgniteFsByteDelimiterRecordResolver +org.apache.ignite.ignitefs.mapreduce.records.IgniteFsFixedLengthRecordResolver +org.apache.ignite.ignitefs.mapreduce.records.IgniteFsNewLineRecordResolver +org.apache.ignite.ignitefs.mapreduce.records.IgniteFsStringDelimiterRecordResolver org.apache.ignite.internal.ClusterGroupAdapter org.apache.ignite.internal.ClusterGroupAdapter$AgeProjection org.apache.ignite.internal.ClusterGroupAdapter$AttributeFilter @@ -243,14 +242,15 @@ org.apache.ignite.internal.IgniteKernal$1 org.apache.ignite.internal.IgniteKernal$6 org.apache.ignite.internal.IgniteKernal$7 org.apache.ignite.internal.IgniteKernal$8 -org.apache.ignite.internal.IgniteManagedImpl org.apache.ignite.internal.IgniteMessagingImpl org.apache.ignite.internal.IgniteSchedulerImpl +org.apache.ignite.internal.IgniteServicesImpl org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance$1 org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException org.apache.ignite.internal.cluster.ClusterTopologyCheckedException org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException org.apache.ignite.internal.compute.ComputeTaskTimeoutCheckedException +org.apache.ignite.internal.direct.DirectByteBufferStream$Type org.apache.ignite.internal.executor.GridExecutorService org.apache.ignite.internal.executor.GridExecutorService$1 org.apache.ignite.internal.executor.GridExecutorService$TaskTerminateListener @@ -292,31 +292,34 @@ org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder$WeakQueryFutureIterator org.apache.ignite.internal.processors.cache.GridCacheAdapter$10 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$11$1 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$11 org.apache.ignite.internal.processors.cache.GridCacheAdapter$12 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$13 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$13$1 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$14 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$15 org.apache.ignite.internal.processors.cache.GridCacheAdapter$2 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$22$1 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$24 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$25$1 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$24$1 org.apache.ignite.internal.processors.cache.GridCacheAdapter$26 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$27$1 org.apache.ignite.internal.processors.cache.GridCacheAdapter$28 org.apache.ignite.internal.processors.cache.GridCacheAdapter$3 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$5 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$61 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$62 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$30 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$6 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$63 org.apache.ignite.internal.processors.cache.GridCacheAdapter$64 org.apache.ignite.internal.processors.cache.GridCacheAdapter$65 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$66 org.apache.ignite.internal.processors.cache.GridCacheAdapter$67 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$68 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$69 org.apache.ignite.internal.processors.cache.GridCacheAdapter$7 org.apache.ignite.internal.processors.cache.GridCacheAdapter$70 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$8 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$73 org.apache.ignite.internal.processors.cache.GridCacheAdapter$9 org.apache.ignite.internal.processors.cache.GridCacheAdapter$GlobalClearAllCallable org.apache.ignite.internal.processors.cache.GridCacheAdapter$GlobalSizeCallable org.apache.ignite.internal.processors.cache.GridCacheAdapter$LoadCacheClosure org.apache.ignite.internal.processors.cache.GridCacheAdapter$LoadKeysCallable +org.apache.ignite.internal.processors.cache.GridCacheAdapter$SizeCallable org.apache.ignite.internal.processors.cache.GridCacheAdapter$UpdateGetTimeStatClosure org.apache.ignite.internal.processors.cache.GridCacheAdapter$UpdatePutAndGetTimeStatClosure org.apache.ignite.internal.processors.cache.GridCacheAdapter$UpdatePutTimeStatClosure @@ -394,6 +397,7 @@ org.apache.ignite.internal.processors.cache.GridCacheStoreManager$1 org.apache.ignite.internal.processors.cache.GridCacheStoreManager$2 org.apache.ignite.internal.processors.cache.GridCacheStoreManager$3 org.apache.ignite.internal.processors.cache.GridCacheSwapManager$11 +org.apache.ignite.internal.processors.cache.GridCacheSwapManager$14 org.apache.ignite.internal.processors.cache.GridCacheSwapManager$2 org.apache.ignite.internal.processors.cache.GridCacheSwapManager$3 org.apache.ignite.internal.processors.cache.GridCacheSwapManager$4 @@ -426,6 +430,7 @@ org.apache.ignite.internal.processors.cache.GridCacheUtils$6 org.apache.ignite.internal.processors.cache.GridCacheUtils$7 org.apache.ignite.internal.processors.cache.GridCacheUtils$8 org.apache.ignite.internal.processors.cache.GridCacheUtils$9 +org.apache.ignite.internal.processors.cache.GridCacheValueBytes org.apache.ignite.internal.processors.cache.GridCacheValueCollection org.apache.ignite.internal.processors.cache.GridCacheValueCollection$1 org.apache.ignite.internal.processors.cache.GridCacheWriteBehindStore$StoreOperation @@ -447,6 +452,7 @@ org.apache.ignite.internal.processors.cache.distributed.GridCachePessimisticChec org.apache.ignite.internal.processors.cache.distributed.GridCachePessimisticCheckCommittedTxRequest org.apache.ignite.internal.processors.cache.distributed.GridCachePessimisticCheckCommittedTxResponse org.apache.ignite.internal.processors.cache.distributed.GridCacheTtlUpdateRequest +org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter$1 org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter$GlobalRemoveAllCallable org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockRequest @@ -638,10 +644,10 @@ org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo org.apache.ignite.internal.processors.cache.local.GridLocalLockFuture org.apache.ignite.internal.processors.cache.local.GridLocalTxFuture -org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$3 +org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$10 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$4 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$5 -org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$8 +org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$6 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$9 org.apache.ignite.internal.processors.cache.query.GridCacheDistributedFieldsQueryFuture org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryFuture @@ -885,7 +891,7 @@ org.apache.ignite.internal.processors.fs.IgniteFsFileImpl org.apache.ignite.internal.processors.fs.IgniteFsMetricsAdapter org.apache.ignite.internal.processors.fs.IgniteFsOutputStreamImpl$ReserveSpaceClosure org.apache.ignite.internal.processors.fs.IgniteFsProcessor$1 -org.apache.ignite.internal.processors.fs.IgniteFsProcessor$3 +org.apache.ignite.internal.processors.fs.IgniteFsProcessor$2 org.apache.ignite.internal.processors.fs.IgniteFsTaskArgsImpl org.apache.ignite.internal.processors.hadoop.GridHadoopDefaultJobInfo org.apache.ignite.internal.processors.hadoop.GridHadoopFileBlock @@ -975,18 +981,12 @@ org.apache.ignite.internal.processors.rest.client.message.GridClientCacheQueryRe org.apache.ignite.internal.processors.rest.client.message.GridClientCacheQueryRequest$GridQueryType org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest$GridCacheOperation -org.apache.ignite.internal.processors.rest.client.message.GridClientGetMetaDataRequest org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequest -org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequestWrapper org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeResponse -org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeResponseWrapper org.apache.ignite.internal.processors.rest.client.message.GridClientLogRequest -org.apache.ignite.internal.processors.rest.client.message.GridClientMessageWrapper org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean org.apache.ignite.internal.processors.rest.client.message.GridClientNodeMetricsBean org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacket -org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacketWrapper -org.apache.ignite.internal.processors.rest.client.message.GridClientPutMetaDataRequest org.apache.ignite.internal.processors.rest.client.message.GridClientResponse org.apache.ignite.internal.processors.rest.client.message.GridClientTaskRequest org.apache.ignite.internal.processors.rest.client.message.GridClientTaskResultBean @@ -1021,7 +1021,6 @@ org.apache.ignite.internal.processors.rest.handlers.top.GridTopologyCommandHandl org.apache.ignite.internal.processors.rest.protocols.http.jetty.GridJettyRestProtocol$1 org.apache.ignite.internal.processors.rest.protocols.tcp.GridClientPacketType org.apache.ignite.internal.processors.rest.protocols.tcp.GridMemcachedMessage -org.apache.ignite.internal.processors.rest.protocols.tcp.GridMemcachedMessageWrapper org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpMemcachedNioListener$1 org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpMemcachedNioListener$2 org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpRestNioListener$1 @@ -1040,8 +1039,8 @@ org.apache.ignite.internal.processors.service.GridServiceProcessor$AssignmentLis org.apache.ignite.internal.processors.service.GridServiceProcessor$DeploymentListener org.apache.ignite.internal.processors.service.GridServiceProxy org.apache.ignite.internal.processors.service.GridServiceProxy$ServiceProxyCallable -org.apache.ignite.internal.processors.service.ManagedServiceContextImpl -org.apache.ignite.internal.processors.service.ManagedServiceDescriptorImpl +org.apache.ignite.internal.processors.service.ServiceContextImpl +org.apache.ignite.internal.processors.service.ServiceDescriptorImpl org.apache.ignite.internal.processors.streamer.GridStreamerAttributes org.apache.ignite.internal.processors.streamer.GridStreamerCancelRequest org.apache.ignite.internal.processors.streamer.GridStreamerExecutionBatch @@ -1140,9 +1139,6 @@ org.apache.ignite.internal.util.IgniteUtils$6 org.apache.ignite.internal.util.IgniteUtils$7 org.apache.ignite.internal.util.IgniteUtils$8 org.apache.ignite.internal.util.IgniteUtils$9 -org.apache.ignite.internal.util.direct.GridTcpCommunicationMessageAdapter$1 -org.apache.ignite.internal.util.direct.GridTcpCommunicationMessageAdapter$DummyEnum -org.apache.ignite.internal.util.direct.GridTcpCommunicationMessageState$DummyEnum org.apache.ignite.internal.util.future.GridCompoundFuture$1 org.apache.ignite.internal.util.future.GridCompoundFuture$Listener org.apache.ignite.internal.util.future.GridCompoundIdentityFuture @@ -1180,8 +1176,6 @@ org.apache.ignite.internal.util.lang.GridFunc$1 org.apache.ignite.internal.util.lang.GridFunc$10 org.apache.ignite.internal.util.lang.GridFunc$100 org.apache.ignite.internal.util.lang.GridFunc$101 -org.apache.ignite.internal.util.lang.GridFunc$101$1 -org.apache.ignite.internal.util.lang.GridFunc$101$2 org.apache.ignite.internal.util.lang.GridFunc$102 org.apache.ignite.internal.util.lang.GridFunc$102$1 org.apache.ignite.internal.util.lang.GridFunc$102$2 @@ -1192,6 +1186,8 @@ org.apache.ignite.internal.util.lang.GridFunc$104 org.apache.ignite.internal.util.lang.GridFunc$104$1 org.apache.ignite.internal.util.lang.GridFunc$104$2 org.apache.ignite.internal.util.lang.GridFunc$105 +org.apache.ignite.internal.util.lang.GridFunc$105$1 +org.apache.ignite.internal.util.lang.GridFunc$105$2 org.apache.ignite.internal.util.lang.GridFunc$106 org.apache.ignite.internal.util.lang.GridFunc$107 org.apache.ignite.internal.util.lang.GridFunc$108 @@ -1208,22 +1204,22 @@ org.apache.ignite.internal.util.lang.GridFunc$117 org.apache.ignite.internal.util.lang.GridFunc$118 org.apache.ignite.internal.util.lang.GridFunc$119 org.apache.ignite.internal.util.lang.GridFunc$12 +org.apache.ignite.internal.util.lang.GridFunc$120 org.apache.ignite.internal.util.lang.GridFunc$121 -org.apache.ignite.internal.util.lang.GridFunc$122 +org.apache.ignite.internal.util.lang.GridFunc$123 org.apache.ignite.internal.util.lang.GridFunc$124 -org.apache.ignite.internal.util.lang.GridFunc$125 +org.apache.ignite.internal.util.lang.GridFunc$126 org.apache.ignite.internal.util.lang.GridFunc$127 -org.apache.ignite.internal.util.lang.GridFunc$128 org.apache.ignite.internal.util.lang.GridFunc$129 org.apache.ignite.internal.util.lang.GridFunc$13 +org.apache.ignite.internal.util.lang.GridFunc$130 org.apache.ignite.internal.util.lang.GridFunc$131 -org.apache.ignite.internal.util.lang.GridFunc$132 org.apache.ignite.internal.util.lang.GridFunc$133 org.apache.ignite.internal.util.lang.GridFunc$134 org.apache.ignite.internal.util.lang.GridFunc$135 org.apache.ignite.internal.util.lang.GridFunc$136 +org.apache.ignite.internal.util.lang.GridFunc$137 org.apache.ignite.internal.util.lang.GridFunc$138 -org.apache.ignite.internal.util.lang.GridFunc$139 org.apache.ignite.internal.util.lang.GridFunc$14 org.apache.ignite.internal.util.lang.GridFunc$140 org.apache.ignite.internal.util.lang.GridFunc$141 @@ -1251,6 +1247,8 @@ org.apache.ignite.internal.util.lang.GridFunc$160 org.apache.ignite.internal.util.lang.GridFunc$161 org.apache.ignite.internal.util.lang.GridFunc$162 org.apache.ignite.internal.util.lang.GridFunc$163 +org.apache.ignite.internal.util.lang.GridFunc$164 +org.apache.ignite.internal.util.lang.GridFunc$165 org.apache.ignite.internal.util.lang.GridFunc$17 org.apache.ignite.internal.util.lang.GridFunc$18 org.apache.ignite.internal.util.lang.GridFunc$19 @@ -1335,7 +1333,7 @@ org.apache.ignite.internal.util.lang.GridFunc$9 org.apache.ignite.internal.util.lang.GridFunc$90 org.apache.ignite.internal.util.lang.GridFunc$91 org.apache.ignite.internal.util.lang.GridFunc$92 -org.apache.ignite.internal.util.lang.GridFunc$95 +org.apache.ignite.internal.util.lang.GridFunc$93 org.apache.ignite.internal.util.lang.GridFunc$96 org.apache.ignite.internal.util.lang.GridFunc$97 org.apache.ignite.internal.util.lang.GridFunc$98 @@ -1501,10 +1499,6 @@ org.apache.ignite.internal.visor.node.VisorPeerToPeerConfiguration org.apache.ignite.internal.visor.node.VisorRestConfiguration org.apache.ignite.internal.visor.node.VisorSegmentationConfiguration org.apache.ignite.internal.visor.node.VisorSpisConfiguration -org.apache.ignite.internal.visor.portable.VisorPortableMetadata -org.apache.ignite.internal.visor.portable.VisorPortableMetadataCollectorTask -org.apache.ignite.internal.visor.portable.VisorPortableMetadataCollectorTask$VisorPortableCollectMetadataJob -org.apache.ignite.internal.visor.portable.VisorPortableMetadataField org.apache.ignite.internal.visor.query.VisorQueryCleanupTask org.apache.ignite.internal.visor.query.VisorQueryCleanupTask$VisorQueryCleanupJob org.apache.ignite.internal.visor.query.VisorQueryField @@ -1531,14 +1525,13 @@ org.apache.ignite.lang.IgniteFutureTimeoutException org.apache.ignite.lang.IgniteProductVersion org.apache.ignite.lang.IgniteUuid org.apache.ignite.lifecycle.LifecycleEventType -org.apache.ignite.logger.log4j.IgniteLog4jLogger$1 -org.apache.ignite.logger.log4j.IgniteLog4jLogger$2 -org.apache.ignite.logger.log4j.IgniteLog4jLogger$3 -org.apache.ignite.logger.log4j.IgniteLog4jLogger$4 org.apache.ignite.logger.log4j.IgniteLog4jNodeIdFilePath -org.apache.ignite.managed.ManagedServiceConfiguration -org.apache.ignite.marshaller.jdk.IgniteJdkMarshallerDummySerializable -org.apache.ignite.marshaller.optimized.IgniteOptimizedFieldType +org.apache.ignite.logger.log4j.Log4JLogger$1 +org.apache.ignite.logger.log4j.Log4JLogger$2 +org.apache.ignite.logger.log4j.Log4JLogger$3 +org.apache.ignite.logger.log4j.Log4JLogger$4 +org.apache.ignite.marshaller.jdk.JdkMarshallerDummySerializable +org.apache.ignite.marshaller.optimized.OptimizedFieldType org.apache.ignite.plugin.PluginNotFoundException org.apache.ignite.plugin.PluginValidationException org.apache.ignite.plugin.security.GridSecurityCredentials @@ -1546,8 +1539,7 @@ org.apache.ignite.plugin.security.GridSecurityException org.apache.ignite.plugin.security.GridSecurityPermission org.apache.ignite.plugin.security.GridSecuritySubjectType org.apache.ignite.plugin.segmentation.GridSegmentationPolicy -org.apache.ignite.portables.PortableException -org.apache.ignite.portables.PortableInvalidClassException +org.apache.ignite.services.ServiceConfiguration org.apache.ignite.spi.IgnitePortProtocol org.apache.ignite.spi.IgniteSpiException org.apache.ignite.spi.IgniteSpiMultiException diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/PluginContext.java b/modules/core/src/main/java/org/apache/ignite/plugin/PluginContext.java index ee90976e1af7c..0704700223d78 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/PluginContext.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/PluginContext.java @@ -20,7 +20,6 @@ import org.apache.ignite.*; import org.apache.ignite.cluster.*; import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.spi.*; import java.util.*; @@ -95,10 +94,4 @@ public interface PluginContext { * @param cls Class. */ public void deregisterPorts(Class cls); - - /** - * @param producer Message producer. - * @return Message type code. - */ - public byte registerMessageProducer(GridTcpCommunicationMessageProducer producer); } diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java b/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java index d70e429395d18..a926a408cf5ca 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/PluginProvider.java @@ -46,12 +46,10 @@ public interface PluginProvider { public T plugin(); /** - * TODO remove. - * * @param cls Ignite component class. * @return Ignite component or {@code null} if component is not supported. */ - @Nullable public T createComponent(Class cls); + @Nullable public T createComponent(PluginContext ctx, Class cls); /** * Register extensions. diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java new file mode 100644 index 0000000000000..0603d67be2255 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.plugin.extensions.communication; + +import java.io.*; +import java.nio.*; + +/** + * Base class for all communication messages. + */ +public abstract class MessageAdapter implements Serializable, Cloneable { + /** Message writer. */ + protected MessageWriter writer; + + /** Message reader. */ + protected MessageReader reader; + + /** Whether message type is already written. */ + protected boolean typeWritten; + + /** Current write/read state. */ + protected int state; + + /** + * @param writer Message writer. + */ + public final void setWriter(MessageWriter writer) { + if (this.writer == null) + this.writer = writer; + } + + /** + * @param reader Message reader. + */ + public final void setReader(MessageReader reader) { + if (this.reader == null) + this.reader = reader; + } + + /** + * Writes this message to provided byte buffer. + * + * @param buf Byte buffer. + * @return Whether message was fully written. + */ + public abstract boolean writeTo(ByteBuffer buf); + + /** + * Reads this message from provided byte buffer. + * + * @param buf Byte buffer. + * @return Whether message was fully read. + */ + public abstract boolean readFrom(ByteBuffer buf); + + /** + * Gets message type. + * + * @return Message type. + */ + public abstract byte directType(); + + /** {@inheritDoc} */ + @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException") + @Override public abstract MessageAdapter clone(); + + /** + * Clones all fields of the provided message to this message. + * + * @param msg Message to clone from. + */ + protected abstract void clone0(MessageAdapter msg); + + /** + * Defines whether recovery for this message should be skipped. + * + * @return Whether recovery for this message should be skipped. + */ + public boolean skipRecovery() { + return false; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageFactory.java similarity index 59% rename from modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpMessageFactory.java rename to modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageFactory.java index 7f33cd14fd4a1..f1acedaa0cf64 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpMessageFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageFactory.java @@ -15,15 +15,27 @@ * limitations under the License. */ -package org.apache.ignite.internal.util.direct; +package org.apache.ignite.plugin.extensions.communication; + +import org.apache.ignite.plugin.*; +import org.jetbrains.annotations.*; /** - * + * Factory for communication messages. + *

      + * A plugin can provide his own message factory as an extension + * if it uses any custom messages (all message must extend + * {@link MessageAdapter} class). */ -public interface GridTcpMessageFactory { +public interface MessageFactory extends Extension { /** + * Creates new message instance of provided type. + *

      + * This method should return {@code null} if provided message type + * is unknown to this factory. + * * @param type Message type. * @return Message instance. */ - public GridTcpCommunicationMessageAdapter create(byte type); + @Nullable public MessageAdapter create(byte type); } diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageCallback.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageFormatter.java similarity index 57% rename from modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageCallback.java rename to modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageFormatter.java index c347858f333d0..796b31764536a 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageCallback.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageFormatter.java @@ -19,30 +19,28 @@ import org.apache.ignite.plugin.*; -import java.nio.*; -import java.util.*; - /** - * Allows to patch message before sending or after reading. + * Provides a custom format for communication messages. + *

      + * A plugin can provide his own message factory as an extension + * to replace default format of communication messages. + *

      + * Note that only one custom formatter is allowed. If two + * plugins provide different formatters, exception will + * be thrown on node startup. */ -public interface MessageCallback extends Extension { +public interface MessageFormatter extends Extension { /** - * Writes delta for provided node and message type. + * Creates new message writer instance. * - * @param nodeId Node ID. - * @param msg Message type. - * @param buf Buffer to write to. - * @return Whether delta was fully written. + * @return Message writer. */ - public boolean onSend(UUID nodeId, Object msg, ByteBuffer buf); + public MessageWriter writer(); /** - * Reads delta for provided node and message type. + * Creates new message reader instance. * - * @param nodeId Node ID. - * @param msgCls Message type. - * @param buf Buffer to read from. - * @return Whether delta was fully read. + * @return Message reader. */ - public boolean onReceive(UUID nodeId, Class msgCls, ByteBuffer buf); + public MessageReader reader(); } diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java new file mode 100644 index 0000000000000..a2c1a68697e40 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java @@ -0,0 +1,252 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.plugin.extensions.communication; + +import org.apache.ignite.lang.*; + +import java.nio.*; +import java.util.*; + +/** + * Communication message reader. + *

      + * Allows to customize the binary format of communication messages. + */ +public interface MessageReader { + /** + * Sets but buffer to read from. + * + * @param buf Byte buffer. + */ + public void setBuffer(ByteBuffer buf); + + /** + * Reads {@code byte} value. + * + * @param name Field name. + * @return {@code byte} value. + */ + public byte readByte(String name); + + /** + * Reads {@code short} value. + * + * @param name Field name. + * @return {@code short} value. + */ + public short readShort(String name); + + /** + * Reads {@code int} value. + * + * @param name Field name. + * @return {@code int} value. + */ + public int readInt(String name); + + /** + * Reads {@code long} value. + * + * @param name Field name. + * @return {@code long} value. + */ + public long readLong(String name); + + /** + * Reads {@code float} value. + * + * @param name Field name. + * @return {@code float} value. + */ + public float readFloat(String name); + + /** + * Reads {@code double} value. + * + * @param name Field name. + * @return {@code double} value. + */ + public double readDouble(String name); + + /** + * Reads {@code char} value. + * + * @param name Field name. + * @return {@code char} value. + */ + public char readChar(String name); + + /** + * Reads {@code boolean} value. + * + * @param name Field name. + * @return {@code boolean} value. + */ + public boolean readBoolean(String name); + + /** + * Reads {@code byte} array. + * + * @param name Field name. + * @return {@code byte} array. + */ + public byte[] readByteArray(String name); + + /** + * Reads {@code short} array. + * + * @param name Field name. + * @return {@code short} array. + */ + public short[] readShortArray(String name); + + /** + * Reads {@code int} array. + * + * @param name Field name. + * @return {@code int} array. + */ + public int[] readIntArray(String name); + + /** + * Reads {@code long} array. + * + * @param name Field name. + * @return {@code long} array. + */ + public long[] readLongArray(String name); + + /** + * Reads {@code float} array. + * + * @param name Field name. + * @return {@code float} array. + */ + public float[] readFloatArray(String name); + + /** + * Reads {@code double} array. + * + * @param name Field name. + * @return {@code double} array. + */ + public double[] readDoubleArray(String name); + + /** + * Reads {@code char} array. + * + * @param name Field name. + * @return {@code char} array. + */ + public char[] readCharArray(String name); + + /** + * Reads {@code boolean} array. + * + * @param name Field name. + * @return {@code boolean} array. + */ + public boolean[] readBooleanArray(String name); + + /** + * Reads {@link String}. + * + * @param name Field name. + * @return {@link String}. + */ + public String readString(String name); + + /** + * Reads {@link BitSet}. + * + * @param name Field name. + * @return {@link BitSet}. + */ + public BitSet readBitSet(String name); + + /** + * Reads {@link UUID}. + * + * @param name Field name. + * @return {@link UUID}. + */ + public UUID readUuid(String name); + + /** + * Reads {@link IgniteUuid}. + * + * @param name Field name. + * @return {@link IgniteUuid}. + */ + public IgniteUuid readIgniteUuid(String name); + + /** + * Reads {@code enum} value. + * + * @param name Field name. + * @param enumCls {@code enum} type. + * @return {@code enum} value. + */ + public > T readEnum(String name, Class enumCls); + + /** + * Reads nested message. + * + * @param name Field name. + * @return Message. + */ + public T readMessage(String name); + + /** + * Reads array of objects. + * + * @param name Field name. + * @param itemCls Array component type. + * @return Array of objects. + */ + public T[] readObjectArray(String name, Class itemCls); + + /** + * Reads collection. + * + * @param name Field name. + * @param itemCls Collection item type. + * @return Collection. + */ + public , T> C readCollection(String name, Class itemCls); + + /** + * Reads map. + * + * @param name Field name. + * @param keyCls Map key type. + * @param valCls Map value type. + * @param linked Whether {@link LinkedHashMap} should be created. + * @return Map. + */ + public , K, V> M readMap(String name, Class keyCls, Class valCls, boolean linked); + + /** + * Tells whether last invocation of any of {@code readXXX(...)} + * methods has fully written the value. {@code False} is returned + * if there were not enough remaining bytes in byte buffer. + * + * @return Whether las value was fully read. + */ + public boolean isLastRead(); +} diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageWriter.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageWriter.java new file mode 100644 index 0000000000000..89c55a33e191b --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageWriter.java @@ -0,0 +1,266 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.plugin.extensions.communication; + +import org.apache.ignite.lang.*; + +import java.nio.*; +import java.util.*; + +/** + * Communication message writer. + *

      + * Allows to customize the binary format of communication messages. + */ +public interface MessageWriter { + /** + * Sets but buffer to write to. + * + * @param buf Byte buffer. + */ + public void setBuffer(ByteBuffer buf); + + /** + * Writes {@code byte} value. + * + * @param name Field name. + * @param val {@code byte} value. + * @return Whether value was fully written. + */ + public boolean writeByte(String name, byte val); + + /** + * Writes {@code short} value. + * + * @param name Field name. + * @param val {@code short} value. + * @return Whether value was fully written. + */ + public boolean writeShort(String name, short val); + + /** + * Writes {@code int} value. + * + * @param name Field name. + * @param val {@code int} value. + * @return Whether value was fully written. + */ + public boolean writeInt(String name, int val); + + /** + * Writes {@code long} value. + * + * @param name Field name. + * @param val {@code long} value. + * @return Whether value was fully written. + */ + public boolean writeLong(String name, long val); + + /** + * Writes {@code float} value. + * + * @param name Field name. + * @param val {@code float} value. + * @return Whether value was fully written. + */ + public boolean writeFloat(String name, float val); + + /** + * Writes {@code double} value. + * + * @param name Field name. + * @param val {@code double} value. + * @return Whether value was fully written. + */ + public boolean writeDouble(String name, double val); + + /** + * Writes {@code char} value. + * + * @param name Field name. + * @param val {@code char} value. + * @return Whether value was fully written. + */ + public boolean writeChar(String name, char val); + + /** + * Writes {@code boolean} value. + * + * @param name Field name. + * @param val {@code boolean} value. + * @return Whether value was fully written. + */ + public boolean writeBoolean(String name, boolean val); + + /** + * Writes {@code byte} array. + * + * @param name Field name. + * @param val {@code byte} array. + * @return Whether array was fully written. + */ + public boolean writeByteArray(String name, byte[] val); + + /** + * Writes {@code short} array. + * + * @param name Field name. + * @param val {@code short} array. + * @return Whether array was fully written. + */ + public boolean writeShortArray(String name, short[] val); + + /** + * Writes {@code int} array. + * + * @param name Field name. + * @param val {@code int} array. + * @return Whether array was fully written. + */ + public boolean writeIntArray(String name, int[] val); + + /** + * Writes {@code long} array. + * + * @param name Field name. + * @param val {@code long} array. + * @return Whether array was fully written. + */ + public boolean writeLongArray(String name, long[] val); + + /** + * Writes {@code float} array. + * + * @param name Field name. + * @param val {@code float} array. + * @return Whether array was fully written. + */ + public boolean writeFloatArray(String name, float[] val); + + /** + * Writes {@code double} array. + * + * @param name Field name. + * @param val {@code double} array. + * @return Whether array was fully written. + */ + public boolean writeDoubleArray(String name, double[] val); + + /** + * Writes {@code char} array. + * + * @param name Field name. + * @param val {@code char} array. + * @return Whether array was fully written. + */ + public boolean writeCharArray(String name, char[] val); + + /** + * Writes {@code boolean} array. + * + * @param name Field name. + * @param val {@code boolean} array. + * @return Whether array was fully written. + */ + public boolean writeBooleanArray(String name, boolean[] val); + + /** + * Writes {@link String}. + * + * @param name Field name. + * @param val {@link String}. + * @return Whether value was fully written. + */ + public boolean writeString(String name, String val); + + /** + * Writes {@link BitSet}. + * + * @param name Field name. + * @param val {@link BitSet}. + * @return Whether value was fully written. + */ + public boolean writeBitSet(String name, BitSet val); + + /** + * Writes {@link UUID}. + * + * @param name Field name. + * @param val {@link UUID}. + * @return Whether value was fully written. + */ + public boolean writeUuid(String name, UUID val); + + /** + * Writes {@link IgniteUuid}. + * + * @param name Field name. + * @param val {@link IgniteUuid}. + * @return Whether value was fully written. + */ + public boolean writeIgniteUuid(String name, IgniteUuid val); + + /** + * Writes {@code enum} value. + * + * @param name Field name. + * @param val {@code enum} value. + * @return Whether value was fully written. + */ + public boolean writeEnum(String name, Enum val); + + /** + * Writes nested message. + * + * @param name Field name. + * @param val Message. + * @return Whether value was fully written. + */ + public boolean writeMessage(String name, MessageAdapter val); + + /** + * Writes array of objects. + * + * @param name Field name. + * @param arr Array of objects. + * @param itemCls Array component type. + * @return Whether array was fully written. + */ + public boolean writeObjectArray(String name, T[] arr, Class itemCls); + + /** + * Writes collection. + * + * @param name Field name. + * @param col Collection. + * @param itemCls Collection item type. + * @return Whether value was fully written. + */ + public boolean writeCollection(String name, Collection col, Class itemCls); + + /** + * Writes map. + * + * @param name Field name. + * @param map Map. + * @param keyCls Map key type. + * @param valCls Map value type. + * @return Whether value was fully written. + */ + public boolean writeMap(String name, Map map, Class keyCls, Class valCls); +} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/package.html b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/package.html similarity index 94% rename from modules/core/src/main/java/org/apache/ignite/portables/package.html rename to modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/package.html index 4c645bed3366c..6444222525b51 100644 --- a/modules/core/src/main/java/org/apache/ignite/portables/package.html +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/package.html @@ -19,6 +19,6 @@ - Contains Portable Objects related functionality. + Contains extendable components for communication. diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/security/GridSecurityCredentials.java b/modules/core/src/main/java/org/apache/ignite/plugin/security/GridSecurityCredentials.java index 78f7abc4c453a..79dafd36517fe 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/security/GridSecurityCredentials.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/security/GridSecurityCredentials.java @@ -17,10 +17,10 @@ package org.apache.ignite.plugin.security; +import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import org.jetbrains.annotations.*; import java.io.*; @@ -31,7 +31,7 @@ * client or node startup in configuration. *

      * For grid node, security credentials provider is specified in - * {@link org.apache.ignite.configuration.IgniteConfiguration#setSecurityCredentialsProvider(GridSecurityCredentialsProvider)} + * {@link IgniteConfiguration#setSecurityCredentialsProvider(GridSecurityCredentialsProvider)} * configuration property. For Java clients, you can provide credentials in * {@code GridClientConfiguration.setSecurityCredentialsProvider(...)} method. *

      @@ -45,7 +45,7 @@ * specifying {@link #setUserObject(Object) userObject} as well, which can be used * to pass in any additional information required for authentication. */ -public class GridSecurityCredentials implements Externalizable, PortableMarshalAware { +public class GridSecurityCredentials implements Externalizable { /** */ private static final long serialVersionUID = -2655741071578326256L; @@ -183,20 +183,6 @@ public void setUserObject(@Nullable Object userObj) { return res; } - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - writer.rawWriter().writeObject(login); - writer.rawWriter().writeObject(password); - writer.rawWriter().writeObject(userObj); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - login = reader.rawReader().readObject(); - password = reader.rawReader().readObject(); - userObj = reader.rawReader().readObject(); - } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridSecurityCredentials.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableBuilder.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableBuilder.java deleted file mode 100644 index 619081c844d24..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableBuilder.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.jetbrains.annotations.*; - -/** - * Portable object builder. Provides ability to build portable objects dynamically - * without having class definitions. - *

      - * Here is an example of how a portable object can be built dynamically: - *

      - * GridPortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
      - *
      - * builder.setField("fieldA", "A");
      - * builder.setField("fieldB", "B");
      - *
      - * GridPortableObject portableObj = builder.build();
      - * 
      - * - *

      - * Also builder can be initialized by existing portable object. This allows changing some fields without affecting - * other fields. - *

      - * GridPortableBuilder builder = Ignition.ignite().portables().builder(person);
      - *
      - * builder.setField("name", "John");
      - *
      - * person = builder.build();
      - * 
      - *

      - * - * If you need to modify nested portable object you can get builder for nested object using - * {@link #getField(String)}, changes made on nested builder will affect parent object, - * for example: - * - *
      - * GridPortableBuilder personBuilder = grid.portables().createBuilder(personPortableObj);
      - * GridPortableBuilder addressBuilder = personBuilder.setField("address");
      - *
      - * addressBuilder.setField("city", "New York");
      - *
      - * personPortableObj = personBuilder.build();
      - *
      - * // Should be "New York".
      - * String city = personPortableObj.getField("address").getField("city");
      - * 
      - * - * @see org.apache.ignite.IgnitePortables#builder(int) - * @see org.apache.ignite.IgnitePortables#builder(String) - * @see org.apache.ignite.IgnitePortables#builder(PortableObject) - */ -public interface PortableBuilder { - /** - * Returns value assigned to the specified field. - * If the value is a portable object instance of {@code GridPortableBuilder} will be returned, - * which can be modified. - *

      - * Collections and maps returned from this method are modifiable. - * - * @param name Field name. - * @return Filed value. - */ - public T getField(String name); - - /** - * Sets field value. - * - * @param name Field name. - * @param val Field value (cannot be {@code null}). - * @see PortableObject#metaData() - */ - public PortableBuilder setField(String name, Object val); - - /** - * Sets field value with value type specification. - *

      - * Field type is needed for proper metadata update. - * - * @param name Field name. - * @param val Field value. - * @param type Field type. - * @see PortableObject#metaData() - */ - public PortableBuilder setField(String name, @Nullable T val, Class type); - - /** - * Sets field value. - *

      - * This method should be used if field is portable object. - * - * @param name Field name. - * @param builder Builder for object field. - */ - public PortableBuilder setField(String name, @Nullable PortableBuilder builder); - - /** - * Removes field from this builder. - * - * @param fieldName Field name. - * @return {@code this} instance for chaining. - */ - public PortableBuilder removeField(String fieldName); - - /** - * Sets hash code for resulting portable object returned by {@link #build()} method. - *

      - * If not set {@code 0} is used. - * - * @param hashCode Hash code. - * @return {@code this} instance for chaining. - */ - public PortableBuilder hashCode(int hashCode); - - /** - * Builds portable object. - * - * @return Portable object. - * @throws PortableException In case of error. - */ - public PortableObject build() throws PortableException; -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableConfiguration.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableConfiguration.java deleted file mode 100644 index 967f8cdd4556d..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableConfiguration.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.sql.*; -import java.util.*; - -/** - * Defines configuration for Ignite portable functionality. All configuration - * properties defined here can be overridden on per-type level in - * {@link PortableTypeConfiguration}. Type configurations are provided via - * {@link #getTypeConfigurations()} method. - */ -public class PortableConfiguration { - /** Class names. */ - private Collection clsNames; - - /** ID mapper. */ - private PortableIdMapper idMapper; - - /** Serializer. */ - private PortableSerializer serializer; - - /** Types. */ - private Collection typeCfgs; - - /** Use timestamp flag. */ - private boolean useTs = true; - - /** Meta data enabled flag. */ - private boolean metaDataEnabled = true; - - /** Keep deserialized flag. */ - private boolean keepDeserialized = true; - - /** - * Gets class names. - * - * @return Class names. - */ - public Collection getClassNames() { - return clsNames; - } - - /** - * Sets class names. - * - * @param clsNames Class names. - */ - public void setClassNames(Collection clsNames) { - this.clsNames = clsNames; - } - - /** - * Gets ID mapper. - * - * @return ID mapper. - */ - public PortableIdMapper getIdMapper() { - return idMapper; - } - - /** - * Sets ID mapper. - * - * @param idMapper ID mapper. - */ - public void setIdMapper(PortableIdMapper idMapper) { - this.idMapper = idMapper; - } - - /** - * Gets serializer. - * - * @return Serializer. - */ - public PortableSerializer getSerializer() { - return serializer; - } - - /** - * Sets serializer. - * - * @param serializer Serializer. - */ - public void setSerializer(PortableSerializer serializer) { - this.serializer = serializer; - } - - /** - * Gets types configuration. - * - * @return Types configuration. - */ - public Collection getTypeConfigurations() { - return typeCfgs; - } - - /** - * Sets type configurations. - * - * @param typeCfgs Type configurations. - */ - public void setTypeConfigurations(Collection typeCfgs) { - this.typeCfgs = typeCfgs; - } - - /** - * If {@code true} then date values converted to {@link Timestamp} on deserialization. - *

      - * Default value is {@code true}. - * - * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. - */ - public boolean isUseTimestamp() { - return useTs; - } - - /** - * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. - */ - public void setUseTimestamp(boolean useTs) { - this.useTs = useTs; - } - - /** - * If {@code true}, meta data will be collected or all types. If you need to override this behaviour for - * some specific type, use {@link PortableTypeConfiguration#setMetaDataEnabled(Boolean)} method. - *

      - * Default value if {@code true}. - * - * @return Whether meta data is collected. - */ - public boolean isMetaDataEnabled() { - return metaDataEnabled; - } - - /** - * @param metaDataEnabled Whether meta data is collected. - */ - public void setMetaDataEnabled(boolean metaDataEnabled) { - this.metaDataEnabled = metaDataEnabled; - } - - /** - * If {@code true}, {@link PortableObject} will cache deserialized instance after - * {@link PortableObject#deserialize()} is called. All consequent calls of this - * method on the same instance of {@link PortableObject} will return that cached - * value without actually deserializing portable object. If you need to override this - * behaviour for some specific type, use {@link PortableTypeConfiguration#setKeepDeserialized(Boolean)} - * method. - *

      - * Default value if {@code true}. - * - * @return Whether deserialized value is kept. - */ - public boolean isKeepDeserialized() { - return keepDeserialized; - } - - /** - * @param keepDeserialized Whether deserialized value is kept. - */ - public void setKeepDeserialized(boolean keepDeserialized) { - this.keepDeserialized = keepDeserialized; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(PortableConfiguration.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableException.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableException.java deleted file mode 100644 index 63ac1e5acec42..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.apache.ignite.*; -import org.jetbrains.annotations.*; - -/** - * Exception indicating portable object serialization error. - */ -public class PortableException extends IgniteException { - /** */ - private static final long serialVersionUID = 0L; - - /** - * Creates portable exception with error message. - * - * @param msg Error message. - */ - public PortableException(String msg) { - super(msg); - } - - /** - * Creates portable exception with {@link Throwable} as a cause. - * - * @param cause Cause. - */ - public PortableException(Throwable cause) { - super(cause); - } - - /** - * Creates portable exception with error message and {@link Throwable} as a cause. - * - * @param msg Error message. - * @param cause Cause. - */ - public PortableException(String msg, @Nullable Throwable cause) { - super(msg, cause); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableIdMapper.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableIdMapper.java deleted file mode 100644 index f3316de4e81b9..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableIdMapper.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -/** - * Type and field ID mapper for portable objects. Ignite never writes full - * strings for field or type names. Instead, for performance reasons, Ignite - * writes integer hash codes for type and field names. It has been tested that - * hash code conflicts for the type names or the field names - * within the same type are virtually non-existent and, to gain performance, it is safe - * to work with hash codes. For the cases when hash codes for different types or fields - * actually do collide {@code GridPortableIdMapper} allows to override the automatically - * generated hash code IDs for the type and field names. - *

      - * Portable ID mapper can be configured for all portable objects via - * {@link PortableConfiguration#getIdMapper()} method, or for a specific - * portable type via {@link PortableTypeConfiguration#getIdMapper()} method. - */ -public interface PortableIdMapper { - /** - * Gets type ID for provided class name. - *

      - * If {@code 0} is returned, hash code of class simple name will be used. - * - * @param clsName Class name. - * @return Type ID. - */ - public int typeId(String clsName); - - /** - * Gets ID for provided field. - *

      - * If {@code 0} is returned, hash code of field name will be used. - * - * @param typeId Type ID. - * @param fieldName Field name. - * @return Field ID. - */ - public int fieldId(int typeId, String fieldName); -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableInvalidClassException.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableInvalidClassException.java deleted file mode 100644 index 01500ec1e8136..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableInvalidClassException.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.jetbrains.annotations.*; - -/** - * Exception indicating that class needed for deserialization of portable object does not exist. - *

      - * Thrown from {@link PortableObject#deserialize()} method. - */ -public class PortableInvalidClassException extends PortableException { - /** */ - private static final long serialVersionUID = 0L; - - /** - * Creates invalid class exception with error message. - * - * @param msg Error message. - */ - public PortableInvalidClassException(String msg) { - super(msg); - } - - /** - * Creates invalid class exception with {@link Throwable} as a cause. - * - * @param cause Cause. - */ - public PortableInvalidClassException(Throwable cause) { - super(cause); - } - - /** - * Creates invalid class exception with error message and {@link Throwable} as a cause. - * - * @param msg Error message. - * @param cause Cause. - */ - public PortableInvalidClassException(String msg, @Nullable Throwable cause) { - super(msg, cause); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableMarshalAware.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableMarshalAware.java deleted file mode 100644 index b2813a58e0f9e..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableMarshalAware.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -/** - * Interface that allows to implement custom serialization - * logic for portable objects. Portable objects are not required - * to implement this interface, in which case Ignite will automatically - * serialize portable objects using reflection. - *

      - * This interface, in a way, is analogous to {@link java.io.Externalizable} - * interface, which allows users to override default serialization logic, - * usually for performance reasons. The only difference here is that portable - * serialization is already very fast and implementing custom serialization - * logic for portables does not provide significant performance gains. - */ -public interface PortableMarshalAware { - /** - * Writes fields to provided writer. - * - * @param writer Portable object writer. - * @throws PortableException In case of error. - */ - public void writePortable(PortableWriter writer) throws PortableException; - - /** - * Reads fields from provided reader. - * - * @param reader Portable object reader. - * @throws PortableException In case of error. - */ - public void readPortable(PortableReader reader) throws PortableException; -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableMetadata.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableMetadata.java deleted file mode 100644 index 25daf94dacc0d..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableMetadata.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * Portable type meta data. Metadata for portable types can be accessed from any of the - * {@link org.apache.ignite.IgnitePortables#metadata(String) GridPortables.metadata(...)} methods. - * Having metadata also allows for proper formatting of {@code GridPortableObject.toString()} method, - * even when portable objects are kept in binary format only, which may be necessary for audit reasons. - */ -public interface PortableMetadata { - /** - * Gets portable type name. - * - * @return Portable type name. - */ - public String typeName(); - - /** - * Gets collection of all field names for this portable type. - * - * @return Collection of all field names for this portable type. - */ - public Collection fields(); - - /** - * Gets name of the field type for a given field. - * - * @param fieldName Field name. - * @return Field type name. - */ - @Nullable public String fieldTypeName(String fieldName); - - /** - * Portable objects can optionally specify custom key-affinity mapping in the - * configuration. This method returns the name of the field which should be - * used for the key-affinity mapping. - * - * @return Affinity key field name. - */ - @Nullable public String affinityKeyFieldName(); -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableObject.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableObject.java deleted file mode 100644 index 40deabf25f6c8..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableObject.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; - -/** - * Wrapper for portable object in portable binary format. Once an object is defined as portable, - * Ignite will always store it in memory in the portable (i.e. binary) format. - * User can choose to work either with the portable format or with the deserialized form - * (assuming that class definitions are present in the classpath). - *

      - * NOTE: user does not need to (and should not) implement this interface directly. - *

      - * To work with the portable format directly, user should create a cache projection - * over {@code GridPortableObject} class and then retrieve individual fields as needed: - *

      - * CacheProjection<GridPortableObject.class, GridPortableObject.class> prj =
      - *     cache.projection(GridPortableObject.class, GridPortableObject.class);
      - *
      - * // Convert instance of MyKey to portable format.
      - * // We could also use GridPortableBuilder to create
      - * // the key in portable format directly.
      - * GridPortableObject key = grid.portables().toPortable(new MyKey());
      - *
      - * GridPortableObject val = prj.get(key);
      - *
      - * String field = val.field("myFieldName");
      - * 
      - * Alternatively, we could also choose a hybrid approach, where, for example, - * the keys are concrete deserialized objects and the values are returned in portable - * format, like so: - *
      - * CacheProjection<MyKey.class, GridPortableObject.class> prj =
      - *     cache.projection(MyKey.class, GridPortableObject.class);
      - *
      - * GridPortableObject val = prj.get(new MyKey());
      - *
      - * String field = val.field("myFieldName");
      - * 
      - * We could also have the values as concrete deserialized objects and the keys in portable format, - * but such use case is a lot less common because cache keys are usually a lot smaller than values, and - * it may be very cheap to deserialize the keys, but not the values. - *

      - * And finally, if we have class definitions in the classpath, we may choose to work with deserialized - * typed objects at all times. In this case we do incur the deserialization cost, however, - * Ignite will only deserialize on the first access and will cache the deserialized object, - * so it does not have to be deserialized again: - *

      - * CacheProjection<MyKey.class, MyValue.class> prj =
      - *     cache.projection(MyKey.class, MyValue.class);
      - *
      - * MyValue val = prj.get(new MyKey());
      - *
      - * // Normal java getter.
      - * String fieldVal = val.getMyFieldName();
      - * 
      - *

      Working With Maps and Collections

      - * All maps and collections in the portable objects are serialized automatically. When working - * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most - * adequate collection or map in either language. For example, {@link ArrayList} in Java will become - * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap} - * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary} - * in C#, etc. - *

      Dynamic Structure Changes

      - * Since objects are always cached in the portable binary format, server does not need to - * be aware of the class definitions. Moreover, if class definitions are not present or not - * used on the server, then clients can continuously change the structure of the portable - * objects without having to restart the cluster. For example, if one client stores a - * certain class with fields A and B, and another client stores the same class with - * fields B and C, then the server-side portable object will have the fields A, B, and C. - * As the structure of a portable object changes, the new fields become available for SQL queries - * automatically. - *

      Building Portable Objects

      - * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically: - *
      - * GridPortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
      - *
      - * builder.setField("fieldA", "A");
      - * builder.setField("fieldB", "B");
      - *
      - * GridPortableObject portableObj = builder.build();
      - * 
      - * For the cases when class definition is present - * in the class path, it is also possible to populate a standard POJO and then - * convert it to portable format, like so: - *
      - * MyObject obj = new MyObject();
      - *
      - * obj.setFieldA("A");
      - * obj.setFieldB(123);
      - *
      - * GridPortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
      - * 
      - *

      Portable Metadata

      - * Even though Ignite portable protocol only works with hash codes for type and field names - * to achieve better performance, Ignite provides metadata for all portable types which - * can be queried ar runtime via any of the {@link org.apache.ignite.IgnitePortables#metadata(Class) GridPortables.metadata(...)} - * methods. Having metadata also allows for proper formatting of {@code GridPortableObject.toString()} method, - * even when portable objects are kept in binary format only, which may be necessary for audit reasons. - */ -public interface PortableObject extends Serializable, Cloneable { - /** - * Gets portable object type ID. - * - * @return Type ID. - */ - public int typeId(); - - /** - * Gets meta data for this portable object. - * - * @return Meta data. - * @throws PortableException In case of error. - */ - @Nullable public PortableMetadata metaData() throws PortableException; - - /** - * Gets field value. - * - * @param fieldName Field name. - * @return Field value. - * @throws PortableException In case of any other error. - */ - @Nullable public F field(String fieldName) throws PortableException; - - /** - * Gets fully deserialized instance of portable object. - * - * @return Fully deserialized instance of portable object. - * @throws PortableInvalidClassException If class doesn't exist. - * @throws PortableException In case of any other error. - */ - @Nullable public T deserialize() throws PortableException; - - /** - * Copies this portable object. - * - * @return Copy of this portable object. - */ - public PortableObject clone() throws CloneNotSupportedException; -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableRawReader.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableRawReader.java deleted file mode 100644 index 5801aa87b2ed2..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableRawReader.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.jetbrains.annotations.*; - -import java.math.*; -import java.sql.*; -import java.util.*; -import java.util.Date; - -/** - * Raw reader for portable objects. Raw reader does not use field name hash codes, therefore, - * making the format even more compact. However, if the raw reader is used, - * dynamic structure changes to the portable objects are not supported. - */ -public interface PortableRawReader { - /** - * @return Byte value. - * @throws PortableException In case of error. - */ - public byte readByte() throws PortableException; - - /** - * @return Short value. - * @throws PortableException In case of error. - */ - public short readShort() throws PortableException; - - /** - * @return Integer value. - * @throws PortableException In case of error. - */ - public int readInt() throws PortableException; - - /** - * @return Long value. - * @throws PortableException In case of error. - */ - public long readLong() throws PortableException; - - /** - * @return Float value. - * @throws PortableException In case of error. - */ - public float readFloat() throws PortableException; - - /** - * @return Double value. - * @throws PortableException In case of error. - */ - public double readDouble() throws PortableException; - - /** - * @return Char value. - * @throws PortableException In case of error. - */ - public char readChar() throws PortableException; - - /** - * @return Boolean value. - * @throws PortableException In case of error. - */ - public boolean readBoolean() throws PortableException; - - /** - * @return Decimal value. - * @throws PortableException In case of error. - */ - @Nullable public BigDecimal readDecimal() throws PortableException; - - /** - * @return String value. - * @throws PortableException In case of error. - */ - @Nullable public String readString() throws PortableException; - - /** - * @return UUID. - * @throws PortableException In case of error. - */ - @Nullable public UUID readUuid() throws PortableException; - - /** - * @return Date. - * @throws PortableException In case of error. - */ - @Nullable public Date readDate() throws PortableException; - - /** - * @return Timestamp. - * @throws PortableException In case of error. - */ - @Nullable public Timestamp readTimestamp() throws PortableException; - - /** - * @return Object. - * @throws PortableException In case of error. - */ - @Nullable public T readObject() throws PortableException; - - /** - * @return Byte array. - * @throws PortableException In case of error. - */ - @Nullable public byte[] readByteArray() throws PortableException; - - /** - * @return Short array. - * @throws PortableException In case of error. - */ - @Nullable public short[] readShortArray() throws PortableException; - - /** - * @return Integer array. - * @throws PortableException In case of error. - */ - @Nullable public int[] readIntArray() throws PortableException; - - /** - * @return Long array. - * @throws PortableException In case of error. - */ - @Nullable public long[] readLongArray() throws PortableException; - - /** - * @return Float array. - * @throws PortableException In case of error. - */ - @Nullable public float[] readFloatArray() throws PortableException; - - /** - * @return Byte array. - * @throws PortableException In case of error. - */ - @Nullable public double[] readDoubleArray() throws PortableException; - - /** - * @return Char array. - * @throws PortableException In case of error. - */ - @Nullable public char[] readCharArray() throws PortableException; - - /** - * @return Boolean array. - * @throws PortableException In case of error. - */ - @Nullable public boolean[] readBooleanArray() throws PortableException; - - /** - * @return Decimal array. - * @throws PortableException In case of error. - */ - @Nullable public BigDecimal[] readDecimalArray() throws PortableException; - - /** - * @return String array. - * @throws PortableException In case of error. - */ - @Nullable public String[] readStringArray() throws PortableException; - - /** - * @return UUID array. - * @throws PortableException In case of error. - */ - @Nullable public UUID[] readUuidArray() throws PortableException; - - /** - * @return Date array. - * @throws PortableException In case of error. - */ - @Nullable public Date[] readDateArray() throws PortableException; - - /** - * @return Object array. - * @throws PortableException In case of error. - */ - @Nullable public Object[] readObjectArray() throws PortableException; - - /** - * @return Collection. - * @throws PortableException In case of error. - */ - @Nullable public Collection readCollection() throws PortableException; - - /** - * @param colCls Collection class. - * @return Collection. - * @throws PortableException In case of error. - */ - @Nullable public Collection readCollection(Class> colCls) - throws PortableException; - - /** - * @return Map. - * @throws PortableException In case of error. - */ - @Nullable public Map readMap() throws PortableException; - - /** - * @param mapCls Map class. - * @return Map. - * @throws PortableException In case of error. - */ - @Nullable public Map readMap(Class> mapCls) throws PortableException; - - /** - * @param enumCls Enum class. - * @return Value. - * @throws PortableException In case of error. - */ - @Nullable public > T readEnum(Class enumCls) throws PortableException; - - /** - * @param enumCls Enum class. - * @return Value. - * @throws PortableException In case of error. - */ - @Nullable public > T[] readEnumArray(Class enumCls) throws PortableException; -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableRawWriter.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableRawWriter.java deleted file mode 100644 index b8bd48797881f..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableRawWriter.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.jetbrains.annotations.*; - -import java.math.*; -import java.sql.*; -import java.util.*; -import java.util.Date; - -/** - * Raw writer for portable object. Raw writer does not write field name hash codes, therefore, - * making the format even more compact. However, if the raw writer is used, - * dynamic structure changes to the portable objects are not supported. - */ -public interface PortableRawWriter { - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeByte(byte val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeShort(short val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeInt(int val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeLong(long val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeFloat(float val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDouble(double val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeChar(char val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeBoolean(boolean val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDecimal(@Nullable BigDecimal val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeString(@Nullable String val) throws PortableException; - - /** - * @param val UUID to write. - * @throws PortableException In case of error. - */ - public void writeUuid(@Nullable UUID val) throws PortableException; - - /** - * @param val Date to write. - * @throws PortableException In case of error. - */ - public void writeDate(@Nullable Date val) throws PortableException; - - /** - * @param val Timestamp to write. - * @throws PortableException In case of error. - */ - public void writeTimestamp(@Nullable Timestamp val) throws PortableException; - - /** - * @param obj Value to write. - * @throws PortableException In case of error. - */ - public void writeObject(@Nullable Object obj) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeByteArray(@Nullable byte[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeShortArray(@Nullable short[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeIntArray(@Nullable int[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeLongArray(@Nullable long[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeFloatArray(@Nullable float[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDoubleArray(@Nullable double[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeCharArray(@Nullable char[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeBooleanArray(@Nullable boolean[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDecimalArray(@Nullable BigDecimal[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeStringArray(@Nullable String[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeUuidArray(@Nullable UUID[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDateArray(@Nullable Date[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeObjectArray(@Nullable Object[] val) throws PortableException; - - /** - * @param col Collection to write. - * @throws PortableException In case of error. - */ - public void writeCollection(@Nullable Collection col) throws PortableException; - - /** - * @param map Map to write. - * @throws PortableException In case of error. - */ - public void writeMap(@Nullable Map map) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public > void writeEnum(T val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public > void writeEnumArray(T[] val) throws PortableException; -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableReader.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableReader.java deleted file mode 100644 index 8059389a0e5bc..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableReader.java +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.jetbrains.annotations.*; - -import java.math.*; -import java.sql.*; -import java.util.*; -import java.util.Date; - -/** - * Reader for portable objects used in {@link PortableMarshalAware} implementations. - * Useful for the cases when user wants a fine-grained control over serialization. - *

      - * Note that Ignite never writes full strings for field or type names. Instead, - * for performance reasons, Ignite writes integer hash codes for type and field names. - * It has been tested that hash code conflicts for the type names or the field names - * within the same type are virtually non-existent and, to gain performance, it is safe - * to work with hash codes. For the cases when hash codes for different types or fields - * actually do collide, Ignite provides {@link PortableIdMapper} which - * allows to override the automatically generated hash code IDs for the type and field names. - */ -public interface PortableReader { - /** - * @param fieldName Field name. - * @return Byte value. - * @throws PortableException In case of error. - */ - public byte readByte(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Short value. - * @throws PortableException In case of error. - */ - public short readShort(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Integer value. - * @throws PortableException In case of error. - */ - public int readInt(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Long value. - * @throws PortableException In case of error. - */ - public long readLong(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @throws PortableException In case of error. - * @return Float value. - */ - public float readFloat(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Double value. - * @throws PortableException In case of error. - */ - public double readDouble(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Char value. - * @throws PortableException In case of error. - */ - public char readChar(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Boolean value. - * @throws PortableException In case of error. - */ - public boolean readBoolean(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Decimal value. - * @throws PortableException In case of error. - */ - @Nullable public BigDecimal readDecimal(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return String value. - * @throws PortableException In case of error. - */ - @Nullable public String readString(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return UUID. - * @throws PortableException In case of error. - */ - @Nullable public UUID readUuid(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Date. - * @throws PortableException In case of error. - */ - @Nullable public Date readDate(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Timestamp. - * @throws PortableException In case of error. - */ - @Nullable public Timestamp readTimestamp(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Object. - * @throws PortableException In case of error. - */ - @Nullable public T readObject(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Byte array. - * @throws PortableException In case of error. - */ - @Nullable public byte[] readByteArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Short array. - * @throws PortableException In case of error. - */ - @Nullable public short[] readShortArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Integer array. - * @throws PortableException In case of error. - */ - @Nullable public int[] readIntArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Long array. - * @throws PortableException In case of error. - */ - @Nullable public long[] readLongArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Float array. - * @throws PortableException In case of error. - */ - @Nullable public float[] readFloatArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Byte array. - * @throws PortableException In case of error. - */ - @Nullable public double[] readDoubleArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Char array. - * @throws PortableException In case of error. - */ - @Nullable public char[] readCharArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Boolean array. - * @throws PortableException In case of error. - */ - @Nullable public boolean[] readBooleanArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Decimal array. - * @throws PortableException In case of error. - */ - @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return String array. - * @throws PortableException In case of error. - */ - @Nullable public String[] readStringArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return UUID array. - * @throws PortableException In case of error. - */ - @Nullable public UUID[] readUuidArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Date array. - * @throws PortableException In case of error. - */ - @Nullable public Date[] readDateArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Object array. - * @throws PortableException In case of error. - */ - @Nullable public Object[] readObjectArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Collection. - * @throws PortableException In case of error. - */ - @Nullable public Collection readCollection(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @param colCls Collection class. - * @return Collection. - * @throws PortableException In case of error. - */ - @Nullable public Collection readCollection(String fieldName, Class> colCls) - throws PortableException; - - /** - * @param fieldName Field name. - * @return Map. - * @throws PortableException In case of error. - */ - @Nullable public Map readMap(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @param mapCls Map class. - * @return Map. - * @throws PortableException In case of error. - */ - @Nullable public Map readMap(String fieldName, Class> mapCls) - throws PortableException; - - /** - * @param fieldName Field name. - * @param enumCls Enum class. - * @return Value. - * @throws PortableException In case of error. - */ - @Nullable public > T readEnum(String fieldName, Class enumCls) throws PortableException; - - /** - * @param fieldName Field name. - * @param enumCls Enum class. - * @return Value. - * @throws PortableException In case of error. - */ - @Nullable public > T[] readEnumArray(String fieldName, Class enumCls) - throws PortableException; - - /** - * Gets raw reader. Raw reader does not use field name hash codes, therefore, - * making the format even more compact. However, if the raw reader is used, - * dynamic structure changes to the portable objects are not supported. - * - * @return Raw reader. - */ - public PortableRawReader rawReader(); -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableSerializer.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableSerializer.java deleted file mode 100644 index 6b343a09f777f..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableSerializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -/** - * Interface that allows to implement custom serialization logic for portable objects. - * Can be used instead of {@link PortableMarshalAware} in case if the class - * cannot be changed directly. - *

      - * Portable serializer can be configured for all portable objects via - * {@link PortableConfiguration#getSerializer()} method, or for a specific - * portable type via {@link PortableTypeConfiguration#getSerializer()} method. - */ -public interface PortableSerializer { - /** - * Writes fields to provided writer. - * - * @param obj Empty object. - * @param writer Portable object writer. - * @throws PortableException In case of error. - */ - public void writePortable(Object obj, PortableWriter writer) throws PortableException; - - /** - * Reads fields from provided reader. - * - * @param obj Empty object - * @param reader Portable object reader. - * @throws PortableException In case of error. - */ - public void readPortable(Object obj, PortableReader reader) throws PortableException; -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableTypeConfiguration.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableTypeConfiguration.java deleted file mode 100644 index 1af4097cc44f9..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableTypeConfiguration.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.sql.*; - -/** - * Defines configuration properties for a specific portable type. Providing per-type - * configuration is optional, as it is generally enough to provide global - * portable configuration in {@link PortableConfiguration} instance. However, - * this class allows you to change configuration properties for a specific - * portable type without affecting configuration for other portable types. - *

      - * Per-type portable configuration can be specified in - * {@link PortableConfiguration#getTypeConfigurations()} method. - */ -public class PortableTypeConfiguration { - /** Class name. */ - private String clsName; - - /** ID mapper. */ - private PortableIdMapper idMapper; - - /** Serializer. */ - private PortableSerializer serializer; - - /** Use timestamp flag. */ - private Boolean useTs; - - /** Meta data enabled flag. */ - private Boolean metaDataEnabled; - - /** Keep deserialized flag. */ - private Boolean keepDeserialized; - - /** Affinity key field name. */ - private String affKeyFieldName; - - /** - */ - public PortableTypeConfiguration() { - // No-op. - } - - /** - * @param clsName Class name. - */ - public PortableTypeConfiguration(String clsName) { - this.clsName = clsName; - } - - /** - * Gets type name. - * - * @return Type name. - */ - public String getClassName() { - return clsName; - } - - /** - * Sets type name. - * - * @param clsName Type name. - */ - public void setClassName(String clsName) { - this.clsName = clsName; - } - - /** - * Gets ID mapper. - * - * @return ID mapper. - */ - public PortableIdMapper getIdMapper() { - return idMapper; - } - - /** - * Sets ID mapper. - * - * @param idMapper ID mapper. - */ - public void setIdMapper(PortableIdMapper idMapper) { - this.idMapper = idMapper; - } - - /** - * Gets serializer. - * - * @return Serializer. - */ - public PortableSerializer getSerializer() { - return serializer; - } - - /** - * Sets serializer. - * - * @param serializer Serializer. - */ - public void setSerializer(PortableSerializer serializer) { - this.serializer = serializer; - } - - /** - * If {@code true} then date values converted to {@link Timestamp} during unmarshalling. - * - * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. - */ - public Boolean isUseTimestamp() { - return useTs; - } - - /** - * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. - */ - public void setUseTimestamp(Boolean useTs) { - this.useTs = useTs; - } - - /** - * Defines whether meta data is collected for this type. If provided, this value will override - * {@link PortableConfiguration#isMetaDataEnabled()} property. - * - * @return Whether meta data is collected. - */ - public Boolean isMetaDataEnabled() { - return metaDataEnabled; - } - - /** - * @param metaDataEnabled Whether meta data is collected. - */ - public void setMetaDataEnabled(Boolean metaDataEnabled) { - this.metaDataEnabled = metaDataEnabled; - } - - /** - * Defines whether {@link PortableObject} should cache deserialized instance. If provided, - * this value will override {@link PortableConfiguration#isKeepDeserialized()} property. - * - * @return Whether deserialized value is kept. - */ - public Boolean isKeepDeserialized() { - return keepDeserialized; - } - - /** - * @param keepDeserialized Whether deserialized value is kept. - */ - public void setKeepDeserialized(Boolean keepDeserialized) { - this.keepDeserialized = keepDeserialized; - } - - /** - * Gets affinity key field name. - * - * @return Affinity key field name. - */ - public String getAffinityKeyFieldName() { - return affKeyFieldName; - } - - /** - * Sets affinity key field name. - * - * @param affKeyFieldName Affinity key field name. - */ - public void setAffinityKeyFieldName(String affKeyFieldName) { - this.affKeyFieldName = affKeyFieldName; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(PortableTypeConfiguration.class, this, super.toString()); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/portables/PortableWriter.java b/modules/core/src/main/java/org/apache/ignite/portables/PortableWriter.java deleted file mode 100644 index 1b44aa3b857f7..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/portables/PortableWriter.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portables; - -import org.jetbrains.annotations.*; - -import java.math.*; -import java.sql.*; -import java.util.*; -import java.util.Date; - -/** - * Writer for portable object used in {@link PortableMarshalAware} implementations. - * Useful for the cases when user wants a fine-grained control over serialization. - *

      - * Note that Ignite never writes full strings for field or type names. Instead, - * for performance reasons, Ignite writes integer hash codes for type and field names. - * It has been tested that hash code conflicts for the type names or the field names - * within the same type are virtually non-existent and, to gain performance, it is safe - * to work with hash codes. For the cases when hash codes for different types or fields - * actually do collide, Ignite provides {@link PortableIdMapper} which - * allows to override the automatically generated hash code IDs for the type and field names. - */ -public interface PortableWriter { - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeByte(String fieldName, byte val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeShort(String fieldName, short val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeInt(String fieldName, int val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeLong(String fieldName, long val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeFloat(String fieldName, float val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDouble(String fieldName, double val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeChar(String fieldName, char val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeBoolean(String fieldName, boolean val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeString(String fieldName, @Nullable String val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val UUID to write. - * @throws PortableException In case of error. - */ - public void writeUuid(String fieldName, @Nullable UUID val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Date to write. - * @throws PortableException In case of error. - */ - public void writeDate(String fieldName, @Nullable Date val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Timestamp to write. - * @throws PortableException In case of error. - */ - public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws PortableException; - - /** - * @param fieldName Field name. - * @param obj Value to write. - * @throws PortableException In case of error. - */ - public void writeObject(String fieldName, @Nullable Object obj) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeByteArray(String fieldName, @Nullable byte[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeShortArray(String fieldName, @Nullable short[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeIntArray(String fieldName, @Nullable int[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeLongArray(String fieldName, @Nullable long[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeFloatArray(String fieldName, @Nullable float[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDoubleArray(String fieldName, @Nullable double[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeCharArray(String fieldName, @Nullable char[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeStringArray(String fieldName, @Nullable String[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDateArray(String fieldName, @Nullable Date[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeObjectArray(String fieldName, @Nullable Object[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param col Collection to write. - * @throws PortableException In case of error. - */ - public void writeCollection(String fieldName, @Nullable Collection col) throws PortableException; - - /** - * @param fieldName Field name. - * @param map Map to write. - * @throws PortableException In case of error. - */ - public void writeMap(String fieldName, @Nullable Map map) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public > void writeEnum(String fieldName, T val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public > void writeEnumArray(String fieldName, T[] val) throws PortableException; - - /** - * Gets raw writer. Raw writer does not write field name hash codes, therefore, - * making the format even more compact. However, if the raw writer is used, - * dynamic structure changes to the portable objects are not supported. - * - * @return Raw writer. - */ - public PortableRawWriter rawWriter(); -} diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java index 9a3fce385d72c..c4518e6a9098f 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java @@ -23,9 +23,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.managers.eventstorage.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.plugin.security.*; import org.apache.ignite.resources.*; import org.apache.ignite.spi.authentication.*; @@ -35,7 +35,6 @@ import javax.management.*; import java.io.*; -import java.nio.*; import java.text.*; import java.util.*; @@ -698,16 +697,6 @@ public ClusterNode node(UUID nodeId) { return null; } - /** {@inheritDoc} */ - @Override public boolean writeDelta(UUID nodeId, Object msg, ByteBuffer buf) { - return false; - } - - /** {@inheritDoc} */ - @Override public boolean readDelta(UUID nodeId, Class msgCls, ByteBuffer buf) { - return false; - } - /** {@inheritDoc} */ @Override public Collection authenticatedSubjects() { return Collections.emptyList(); @@ -724,8 +713,12 @@ public ClusterNode node(UUID nodeId) { return null; } + @Override public MessageFormatter messageFormatter() { + return null; + } + /** {@inheritDoc} */ - @Override public GridTcpMessageFactory messageFactory() { + @Override public MessageFactory messageFactory() { return null; } } diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiContext.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiContext.java index b030a2daca014..5a0a23f8465eb 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiContext.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiContext.java @@ -22,14 +22,13 @@ import org.apache.ignite.events.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.managers.eventstorage.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.plugin.security.*; import org.apache.ignite.spi.swapspace.*; import org.jetbrains.annotations.*; import javax.cache.*; import java.io.*; -import java.nio.*; import java.util.*; /** @@ -348,26 +347,6 @@ public boolean removeFromOffheap(@Nullable String spaceName, int part, Object ke */ @Nullable public IgniteSpiNodeValidationResult validateNode(ClusterNode node); - /** - * Writes delta for provided node and message type. - * - * @param nodeId Node ID. - * @param msg Message. - * @param buf Buffer to write to. - * @return Whether delta was fully written. - */ - public boolean writeDelta(UUID nodeId, Object msg, ByteBuffer buf); - - /** - * Reads delta for provided node and message type. - * - * @param nodeId Node ID. - * @param msgCls Message type. - * @param buf Buffer to read from. - * @return Whether delta was fully read. - */ - public boolean readDelta(UUID nodeId, Class msgCls, ByteBuffer buf); - /** * Gets collection of authenticated subjects together with their permissions. * @@ -398,7 +377,16 @@ public boolean removeFromOffheap(@Nullable String spaceName, int part, Object ke @Nullable ClassLoader ldr) throws IgniteException; /** + * Gets message formatter. + * + * @return Message formatter. + */ + public MessageFormatter messageFormatter(); + + /** + * Gets message factory. + * * @return Message factory. */ - public GridTcpMessageFactory messageFactory(); + public MessageFactory messageFactory(); } diff --git a/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingRequest.java b/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingRequest.java index 691d8ec3cf88e..9a3a0f0d3c2cf 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingRequest.java @@ -17,8 +17,8 @@ package org.apache.ignite.spi.collision.jobstealing; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -26,7 +26,7 @@ /** * Job stealing request. */ -public class JobStealingRequest extends GridTcpCommunicationMessageAdapter { +public class JobStealingRequest extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -56,7 +56,7 @@ int delta() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { JobStealingRequest _clone = new JobStealingRequest(); clone0(_clone); @@ -65,7 +65,7 @@ int delta() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { JobStealingRequest _clone = (JobStealingRequest)_msg; _clone.delta = delta; @@ -74,21 +74,21 @@ int delta() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putInt(delta)) + if (!writer.writeInt("delta", delta)) return false; - commState.idx++; + state++; } @@ -98,16 +98,16 @@ int delta() { /** {@inheritDoc} */ @SuppressWarnings("all") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - if (buf.remaining() < 4) - return false; + delta = reader.readInt("delta"); - delta = commState.getInt(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; } @@ -116,7 +116,7 @@ int delta() { /** {@inheritDoc} */ @Override public byte directType() { - return 78; + return 82; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java index 068553e347c50..2ab05cbec58c6 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java @@ -22,9 +22,14 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.events.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.managers.eventstorage.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; +import org.apache.ignite.resources.*; +import org.apache.ignite.spi.*; +import org.apache.ignite.spi.communication.*; +import org.apache.ignite.thread.*; +import org.apache.ignite.internal.managers.eventstorage.*; import org.apache.ignite.internal.util.future.*; import org.apache.ignite.internal.util.ipc.*; import org.apache.ignite.internal.util.ipc.shmem.*; @@ -33,11 +38,6 @@ import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.worker.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.spi.*; -import org.apache.ignite.spi.communication.*; -import org.apache.ignite.thread.*; import org.jdk8.backport.*; import org.jetbrains.annotations.*; @@ -144,7 +144,7 @@ @IgniteSpiMultipleInstancesSupport(true) @IgniteSpiConsistencyChecked(optional = false) public class TcpCommunicationSpi extends IgniteSpiAdapter - implements CommunicationSpi, TcpCommunicationSpiMBean { + implements CommunicationSpi, TcpCommunicationSpiMBean { /** IPC error message. */ public static final String OUT_OF_RESOURCES_TCP_MSG = "Failed to allocate shared memory segment " + "(switching to TCP, may be slower). For troubleshooting see " + @@ -239,8 +239,8 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter public static final byte HANDSHAKE_MSG_TYPE = -3; /** Server listener. */ - private final GridNioServerListener srvLsnr = - new GridNioServerListenerAdapter() { + private final GridNioServerListener srvLsnr = + new GridNioServerListenerAdapter() { @Override public void onSessionWriteTimeout(GridNioSession ses) { LT.warn(log, null, "Communication SPI Session write timed out (consider increasing " + "'socketWriteTimeout' " + "configuration property) [remoteAddr=" + ses.remoteAddress() + @@ -292,14 +292,14 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter } } - CommunicationListener lsnr0 = lsnr; + CommunicationListener lsnr0 = lsnr; if (lsnr0 != null) lsnr0.onDisconnected(id); } } - @Override public void onMessage(GridNioSession ses, GridTcpCommunicationMessageAdapter msg) { + @Override public void onMessage(GridNioSession ses, MessageAdapter msg) { UUID sndId = ses.meta(NODE_ID_META); if (sndId == null) { @@ -330,13 +330,6 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter ClusterNode locNode = getSpiContext().localNode(); - IgniteProductVersion locVer = locNode.version(); - - IgniteProductVersion rmtVer = rmtNode.version(); - - if (!locVer.equals(rmtVer)) - ses.addMeta(GridNioServer.DIFF_VER_NODE_ID_META_KEY, sndId); - if (ses.remoteAddress() == null) return; @@ -686,7 +679,7 @@ class ConnectClosure implements IgniteInClosure { private double bufSizeRatio = IgniteSystemProperties.getDouble(IGNITE_COMMUNICATION_BUF_RESIZE_RATIO, 0.8); /** NIO server. */ - private GridNioServer nioSrvr; + private GridNioServer nioSrvr; /** Shared memory server. */ private IpcSharedMemoryServerEndpoint shmemSrv; @@ -725,7 +718,7 @@ class ConnectClosure implements IgniteInClosure { private final ConcurrentMap clients = GridConcurrentFactory.newMap(); /** SPI listener. */ - private volatile CommunicationListener lsnr; + private volatile CommunicationListener lsnr; /** Bound port. */ private int boundTcpPort = -1; @@ -788,87 +781,6 @@ class ConnectClosure implements IgniteInClosure { } }; - /** Message reader. */ - private final GridNioMessageReader msgReader = new GridNioMessageReader() { - /** */ - private GridTcpMessageFactory msgFactory; - - @Override public boolean read(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, ByteBuffer buf) { - assert msg != null; - assert buf != null; - - msg.messageReader(this, nodeId); - - boolean finished = msg.readFrom(buf); - - if (finished && nodeId != null) - finished = getSpiContext().readDelta(nodeId, msg.getClass(), buf); - - return finished; - } - - @Nullable @Override public GridTcpMessageFactory messageFactory() { - if (msgFactory == null) - msgFactory = getSpiContext().messageFactory(); - - return msgFactory; - } - }; - - /** Message writer. */ - private final GridNioMessageWriter msgWriter = new GridNioMessageWriter() { - @Override public boolean write(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, ByteBuffer buf) { - assert msg != null; - assert buf != null; - - msg.messageWriter(this, nodeId); - - boolean finished = msg.writeTo(buf); - - if (finished && nodeId != null) - finished = getSpiContext().writeDelta(nodeId, msg, buf); - - return finished; - } - - @Override public int writeFully(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, OutputStream out, - ByteBuffer buf) throws IOException { - assert msg != null; - assert out != null; - assert buf != null; - assert buf.hasArray(); - - msg.messageWriter(this, nodeId); - - boolean finished = false; - int cnt = 0; - - while (!finished) { - finished = msg.writeTo(buf); - - out.write(buf.array(), 0, buf.position()); - - cnt += buf.position(); - - buf.clear(); - } - - if (nodeId != null) { - while (!finished) { - finished = getSpiContext().writeDelta(nodeId, msg.getClass(), buf); - - out.write(buf.array(), 0, buf.position()); - - cnt += buf.position(); - - buf.clear(); - } - } - - return cnt; - } - }; - /** * Sets address resolver. * @@ -1315,7 +1227,7 @@ public void setBufferSizeRatio(double bufSizeRatio) { } /** {@inheritDoc} */ - @Override public void setListener(CommunicationListener lsnr) { + @Override public void setListener(CommunicationListener lsnr) { this.lsnr = lsnr; } @@ -1549,7 +1461,7 @@ public CommunicationListener getListener() { * @return Server instance. * @throws IgniteCheckedException Thrown if it's not possible to create server. */ - private GridNioServer resetNioServer() throws IgniteCheckedException { + private GridNioServer resetNioServer() throws IgniteCheckedException { if (boundTcpPort >= 0) throw new IgniteCheckedException("Tcp NIO server was already created on port " + boundTcpPort); @@ -1558,8 +1470,43 @@ private GridNioServer resetNioServer() throw // If configured TCP port is busy, find first available in range. for (int port = locPort; port < locPort + locPortRange; port++) { try { - GridNioServer srvr = - GridNioServer.builder() + MessageFactory messageFactory = new MessageFactory() { + private MessageFactory impl; + + @Nullable @Override public MessageAdapter create(byte type) { + if (impl == null) + impl = getSpiContext().messageFactory(); + + assert impl != null; + + return impl.create(type); + } + }; + + MessageFormatter messageFormatter = new MessageFormatter() { + private MessageFormatter impl; + + @Override public MessageWriter writer() { + if (impl == null) + impl = getSpiContext().messageFormatter(); + + assert impl != null; + + return impl.writer(); + } + + @Override public MessageReader reader() { + if (impl == null) + impl = getSpiContext().messageFormatter(); + + assert impl != null; + + return impl.reader(); + } + }; + + GridNioServer srvr = + GridNioServer.builder() .address(locHost) .port(port) .listener(srvLsnr) @@ -1574,10 +1521,10 @@ private GridNioServer resetNioServer() throw .sendQueueLimit(msgQueueLimit) .directMode(true) .metricsListener(metricsLsnr) - .messageWriter(msgWriter) .writeTimeout(sockWriteTimeout) - .filters(new GridNioCodecFilter(new GridDirectParser(msgReader, this), log, true), + .filters(new GridNioCodecFilter(new GridDirectParser(messageFactory), log, true), new GridConnectionBytesVerifyFilter(log)) + .messageFormatter(messageFormatter) .build(); boundTcpPort = port; @@ -1756,7 +1703,7 @@ private void checkAttributePresence(ClusterNode node, String attrName) { } /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) throws IgniteSpiException { + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { assert node != null; assert msg != null; @@ -1939,7 +1886,8 @@ else if (log.isDebugEnabled()) GridCommunicationClient client; try { - client = new GridShmemCommunicationClient(metricsLsnr, port, connTimeout, log, msgWriter); + client = new GridShmemCommunicationClient(metricsLsnr, port, connTimeout, log, + getSpiContext().messageFormatter()); } catch (IgniteCheckedException e) { // Reconnect for the second time, if connection is not established. @@ -2080,19 +2028,10 @@ protected GridCommunicationClient createTcpClient(ClusterNode node) throws Ignit recoveryDesc.release(); } - UUID diffVerNodeId = null; - - IgniteProductVersion locVer = getSpiContext().localNode().version(); - IgniteProductVersion rmtVer = node.version(); - - if (!locVer.equals(rmtVer)) - diffVerNodeId = node.id(); - try { Map meta = new HashMap<>(); meta.put(NODE_ID_META, node.id()); - meta.put(GridNioServer.DIFF_VER_NODE_ID_META_KEY, diffVerNodeId); if (recoveryDesc != null) { recoveryDesc.onHandshake(rcvCnt); @@ -2347,8 +2286,8 @@ else if (log.isDebugEnabled()) * @param msg Communication message. * @param msgC Closure to call when message processing finished. */ - protected void notifyListener(UUID sndId, GridTcpCommunicationMessageAdapter msg, IgniteRunnable msgC) { - CommunicationListener lsnr = this.lsnr; + protected void notifyListener(UUID sndId, MessageAdapter msg, IgniteRunnable msgC) { + CommunicationListener lsnr = this.lsnr; if (lsnr != null) // Notify listener of a new message. @@ -2512,13 +2451,13 @@ private ShmemWorker(IpcEndpoint endpoint) { /** {@inheritDoc} */ @Override protected void body() throws InterruptedException { try { - IpcToNioAdapter adapter = new IpcToNioAdapter<>( + IpcToNioAdapter adapter = new IpcToNioAdapter<>( metricsLsnr, log, endpoint, - msgWriter, srvLsnr, - new GridNioCodecFilter(new GridDirectParser(msgReader, TcpCommunicationSpi.this), log, true), + getSpiContext().messageFormatter(), + new GridNioCodecFilter(new GridDirectParser(getSpiContext().messageFactory()), log, true), new GridConnectionBytesVerifyFilter(log) ); @@ -3037,7 +2976,7 @@ else if (log.isDebugEnabled()) * Handshake message. */ @SuppressWarnings("PublicInnerClass") - public static class HandshakeMessage extends GridTcpCommunicationMessageAdapter { + public static class HandshakeMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -3051,7 +2990,7 @@ public static class HandshakeMessage extends GridTcpCommunicationMessageAdapter private long connectCnt; /** - * Default constructor required by {@link GridTcpCommunicationMessageAdapter}. + * Default constructor required by {@link MessageAdapter}. */ public HandshakeMessage() { // No-op. @@ -3137,12 +3076,12 @@ public UUID nodeId() { /** {@inheritDoc} */ @SuppressWarnings("CloneDoesntCallSuperClone") - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { throw new UnsupportedOperationException(); } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter msg) { + @Override protected void clone0(MessageAdapter msg) { // No-op. } @@ -3156,7 +3095,7 @@ public UUID nodeId() { * Recovery acknowledgment message. */ @SuppressWarnings("PublicInnerClass") - public static class RecoveryLastReceivedMessage extends GridTcpCommunicationMessageAdapter { + public static class RecoveryLastReceivedMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -3164,7 +3103,7 @@ public static class RecoveryLastReceivedMessage extends GridTcpCommunicationMess private long rcvCnt; /** - * Default constructor required by {@link GridTcpCommunicationMessageAdapter}. + * Default constructor required by {@link MessageAdapter}. */ public RecoveryLastReceivedMessage() { // No-op. @@ -3213,12 +3152,12 @@ public long received() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { throw new UnsupportedOperationException(); } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter msg) { + @Override protected void clone0(MessageAdapter msg) { // No-op. } @@ -3237,7 +3176,7 @@ public long received() { * Node ID message. */ @SuppressWarnings("PublicInnerClass") - public static class NodeIdMessage extends GridTcpCommunicationMessageAdapter { + public static class NodeIdMessage extends MessageAdapter { /** */ private static final long serialVersionUID = 0L; @@ -3297,12 +3236,12 @@ private NodeIdMessage(UUID nodeId) { /** {@inheritDoc} */ @SuppressWarnings("CloneDoesntCallSuperClone") - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { throw new UnsupportedOperationException(); } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { // No-op. } diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java index b3ad1db59bbf5..8c788c8e15704 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java @@ -81,6 +81,17 @@ public interface SwapSpaceSpi extends IgniteSpi { */ public long count(@Nullable String spaceName) throws IgniteSpiException; + /** + * Gets number of stored entries (keys) in data space with given name. If specified + * space does not exist this method returns {@code 0}. + * + * @param spaceName Space name to get number of entries for. + * @param parts Partitions. + * @return Number of stored entries in specified space. + * @throws org.apache.ignite.spi.IgniteSpiException In case of any errors. + */ + public long count(@Nullable String spaceName, Set parts) throws IgniteSpiException; + /** * Reads stored value as array of bytes by key from data space with given name. * If specified space does not exist this method returns {@code null}. diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java index c164e1d6ec068..ec2ef97735459 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java @@ -324,6 +324,16 @@ public void setReadStripesNumber(int readStripesNum) { return space.count(); } + /** {@inheritDoc} */ + @Override public long count(@Nullable String spaceName, Set parts) throws IgniteSpiException { + Space space = space(spaceName, false); + + if (space == null) + return 0; + + return space.count(parts); + } + /** {@inheritDoc} */ @Nullable @Override public byte[] read(@Nullable String spaceName, SwapKey key, SwapContext ctx) throws IgniteSpiException { @@ -1528,6 +1538,23 @@ public long count() { return cnt.get(); } + /** + * @param parts Partitions. + * @return Total count of keys for given partitions. + */ + public long count(Set parts) { + long cnt = 0; + + for (Integer part : parts) { + ConcurrentMap map = partition(part, false); + + if (map != null) + cnt += map.size(); + } + + return cnt; + } + /** * Clears space. * diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java index 1de07c99769e5..68f6da18e477b 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java @@ -63,6 +63,11 @@ public class NoopSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceSpi { return 0; } + /** {@inheritDoc} */ + @Override public long count(@Nullable String spaceName, Set parts) throws IgniteSpiException { + return 0; + } + /** {@inheritDoc} */ @Override @Nullable public byte[] read(@Nullable String spaceName, SwapKey key, SwapContext ctx) throws IgniteSpiException { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridJobMasterLeaveAwareSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridJobMasterLeaveAwareSelfTest.java index 4e817a3c33fc6..c9ec0e01827eb 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridJobMasterLeaveAwareSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridJobMasterLeaveAwareSelfTest.java @@ -23,11 +23,11 @@ import org.apache.ignite.compute.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.managers.communication.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.resources.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; @@ -732,7 +732,7 @@ private static class CommunicationSpi extends TcpCommunicationSpi { private CountDownLatch waitLatch = new CountDownLatch(1); /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { sendMessage0(node, msg); } @@ -745,7 +745,7 @@ private static class CommunicationSpi extends TcpCommunicationSpi { * @param msg Message to be sent. * @throws org.apache.ignite.spi.IgniteSpiException If failed. */ - private void sendMessage0(ClusterNode node, GridTcpCommunicationMessageAdapter msg) throws IgniteSpiException { + private void sendMessage0(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { if (msg instanceof GridIoMessage) { GridIoMessage msg0 = (GridIoMessage)msg; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java index 1e002770915fc..a26b6175ab787 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java @@ -19,7 +19,8 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; @@ -49,11 +50,11 @@ public class GridCommunicationSendMessageSelfTest extends GridCommonAbstractTest private int bufSize; static { - GridTcpCommunicationMessageFactory.registerCustom(new GridTcpCommunicationMessageProducer() { - @Override public GridTcpCommunicationMessageAdapter create(byte type) { + GridIoMessageFactory.registerCustom(DIRECT_TYPE, new CO() { + @Override public MessageAdapter apply() { return new TestMessage(); } - }, DIRECT_TYPE); + }); } /** {@inheritDoc} */ @@ -141,23 +142,23 @@ private void doSend() throws Exception { } /** */ - private static class TestMessage extends GridTcpCommunicationMessageAdapter { + private static class TestMessage extends MessageAdapter { /** {@inheritDoc} */ @SuppressWarnings("CloneDoesntCallSuperClone") - @Override public GridTcpCommunicationMessageAdapter clone() { - throw new UnsupportedOperationException(); + @Override public MessageAdapter clone() { + return this; } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { // No-op. } /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - return commState.putByte(directType()); + return writer.writeByte(null, directType()); } /** {@inheritDoc} */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridIoManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridIoManagerSelfTest.java index cf89a1f0e67de..d125375517084 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridIoManagerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridIoManagerSelfTest.java @@ -22,9 +22,9 @@ import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.managers.discovery.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.marshaller.jdk.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.junits.*; @@ -183,7 +183,7 @@ private static class TestGridIoManager extends GridIoManager { } /** {@inheritDoc} */ - @Override public void send(ClusterNode node, GridTopic topic, GridTcpCommunicationMessageAdapter msg, + @Override public void send(ClusterNode node, GridTopic topic, MessageAdapter msg, GridIoPolicy plc) throws IgniteCheckedException { // No-op. } @@ -218,15 +218,15 @@ private static class IsEqualCollection extends ArgumentMatcher cache = jcache(); cache.put("key1", 1); @@ -2192,7 +2205,15 @@ public void testRemoveAll() throws Exception { checkSize(F.asSet("key1", "key2", "key3")); - cache.removeAll(F.asSet("key1", "key2")); + IgniteCache asyncCache = cache.withAsync(); + + if (async) { + asyncCache.removeAll(F.asSet("key1", "key2")); + + asyncCache.future().get(); + } + else + cache.removeAll(F.asSet("key1", "key2")); checkSize(F.asSet("key3")); @@ -2205,20 +2226,34 @@ public void testRemoveAll() throws Exception { cache.put("key2", 2); cache.put("key3", 3); - jcache(gridCount() > 1 ? 1 : 0).removeAll(); + if (async) { + IgniteCache asyncCache0 = jcache(gridCount() > 1 ? 1 : 0).withAsync(); - assert cache.localSize() == 0; - long entryCount = hugeRemoveAllEntryCount(); + asyncCache0.removeAll(); + + asyncCache0.future().get(); + } + else + jcache(gridCount() > 1 ? 1 : 0).removeAll(); - for (int i = 0; i < entryCount; i++) + assertEquals(0, cache.localSize()); + long entryCnt = hugeRemoveAllEntryCount(); + + for (int i = 0; i < entryCnt; i++) cache.put(String.valueOf(i), i); - for (int i = 0; i < entryCount; i++) + for (int i = 0; i < entryCnt; i++) assertEquals(Integer.valueOf(i), cache.get(String.valueOf(i))); - cache.removeAll(); + if (async) { + asyncCache.removeAll(); + + asyncCache.future().get(); + } + else + cache.removeAll(); - for (int i = 0; i < entryCount; i++) + for (int i = 0; i < entryCnt; i++) assertNull(cache.get(String.valueOf(i))); } @@ -2508,7 +2543,7 @@ public void testClear() throws Exception { cache.localEvict(Sets.union(ImmutableSet.of("key1", "key2"), keys)); - assert cache.localSize() == 0; + assert cache.localSize(CachePeekMode.ONHEAP) == 0; cache.clear(); @@ -2519,9 +2554,24 @@ public void testClear() throws Exception { } /** - * @throws Exception In case of error. + * @throws Exception If failed. */ public void testGlobalClearAll() throws Exception { + globalClearAll(false); + } + + /** + * @throws Exception If failed. + */ + public void testGlobalClearAllAsync() throws Exception { + globalClearAll(true); + } + + /** + * @param async If {@code true} uses async method. + * @throws Exception If failed. + */ + protected void globalClearAll(boolean async) throws Exception { // Save entries only on their primary nodes. If we didn't do so, clearLocally() will not remove all entries // because some of them were blocked due to having readers. for (int i = 0; i < gridCount(); i++) { @@ -2529,7 +2579,15 @@ public void testGlobalClearAll() throws Exception { jcache(i).put(key, 1); } - jcache().clear(); + if (async) { + IgniteCache asyncCache = jcache().withAsync(); + + asyncCache.clear(); + + asyncCache.future().get(); + } + else + jcache().clear(); for (int i = 0; i < gridCount(); i++) assert jcache(i).localSize() == 0; @@ -2802,8 +2860,7 @@ public void testPeekMode() throws Exception { /** * @throws Exception In case of error. */ - // TODO: IGNITE-206: Enable when fixed. - public void _testEvictExpired() throws Exception { + public void testEvictExpired() throws Exception { IgniteCache cache = jcache(); String key = primaryKeysForCache(cache, 1).get(0); @@ -2831,16 +2888,14 @@ public void _testEvictExpired() throws Exception { assertTrue(cache.localSize() == 0); - // Force reload on primary node. - for (int i = 0; i < gridCount(); i++) { - if (cache(i).affinity().isPrimary(grid(i).localNode(), key)) - load(jcache(i), key, true); - } - - // Will do near get request. load(cache, key, true); - assertEquals((Integer)1, peek(cache, key)); + CacheAffinity aff = ignite(0).affinity(null); + + for (int i = 0; i < gridCount(); i++) { + if (aff.isPrimaryOrBackup(grid(i).cluster().localNode(), key)) + assertEquals((Integer)1, peek(jcache(i), key)); + } } /** @@ -2903,8 +2958,7 @@ public void testPeekExpiredTx() throws Exception { /** * @throws Exception If failed. */ - // TODO: IGNITE-209: Enable when fixed. - public void _testTtlTx() throws Exception { + public void testTtlTx() throws Exception { if (txEnabled()) checkTtl(true, false); } @@ -2912,8 +2966,7 @@ public void _testTtlTx() throws Exception { /** * @throws Exception If failed. */ - // TODO: IGNITE-209: Enable when fixed. - public void _testTtlNoTx() throws Exception { + public void testTtlNoTx() throws Exception { checkTtl(false, false); } @@ -2934,7 +2987,7 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl)); - final GridCache c = cache(); + final IgniteCache c = jcache(); final String key = primaryKeysForCache(jcache(), 1).get(0); @@ -2960,7 +3013,7 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { IgniteTx tx = transactions().txStart(); try { - grid(0).jcache(null).withExpiryPolicy(expiry).put(key, 1); + jcache().withExpiryPolicy(expiry).put(key, 1); } finally { tx.rollback(); @@ -2976,11 +3029,14 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { IgniteTx tx = inTx ? transactions().txStart() : null; try { - grid(0).jcache(null).withExpiryPolicy(expiry).put(key, 1); + jcache().withExpiryPolicy(expiry).put(key, 1); + + if (tx != null) + tx.commit(); } finally { if (tx != null) - tx.commit(); + tx.close(); } long[] expireTimes = new long[gridCount()]; @@ -3004,11 +3060,14 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { tx = inTx ? transactions().txStart() : null; try { - grid(0).jcache(null).withExpiryPolicy(expiry).put(key, 2); + jcache().withExpiryPolicy(expiry).put(key, 2); + + if (tx != null) + tx.commit(); } finally { if (tx != null) - tx.commit(); + tx.close(); } for (int i = 0; i < gridCount(); i++) { @@ -3030,11 +3089,14 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { tx = inTx ? transactions().txStart() : null; try { - grid(0).jcache(null).withExpiryPolicy(expiry).put(key, 3); + jcache().withExpiryPolicy(expiry).put(key, 3); + + if (tx != null) + tx.commit(); } finally { if (tx != null) - tx.commit(); + tx.close(); } for (int i = 0; i < gridCount(); i++) { @@ -3058,11 +3120,14 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { tx = inTx ? transactions().txStart() : null; try { - c.put(key, 4); + jcache().put(key, 4); + + if (tx != null) + tx.commit(); } finally { if (tx != null) - tx.commit(); + tx.close(); } log.info("Put 4 done"); @@ -3115,7 +3180,31 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { // Ensure that old TTL and expire time are not longer "visible". entry = internalCache.peekEx(key); - assert c.entry(key).getValue() == null; + assert c.get(key) == null; + + assertEquals(0, entry.ttl()); + assertEquals(0, entry.expireTime()); + + // Ensure that next update will not pick old expire time. + + tx = inTx ? transactions().txStart() : null; + + try { + jcache().put(key, 10); + + if (tx != null) + tx.commit(); + } + finally { + if (tx != null) + tx.close(); + } + + U.sleep(2000); + + entry = internalCache.peekEx(key); + + assertEquals((Integer)10, c.get(key)); assertEquals(0, entry.ttl()); assertEquals(0, entry.expireTime()); @@ -3124,8 +3213,7 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { /** * @throws Exception In case of error. */ - // TODO: IGNITE-206: Enable when fixed. - public void _testLocalEvict() throws Exception { + public void testLocalEvict() throws Exception { IgniteCache cache = jcache(); List keys = primaryKeysForCache(cache, 3); @@ -3148,14 +3236,20 @@ public void _testLocalEvict() throws Exception { assert cache.localPeek(key2, CachePeekMode.ONHEAP) == null; assert cache.localPeek(key3, CachePeekMode.ONHEAP) == 3; - if (cache.getConfiguration(CacheConfiguration.class).getDistributionMode() == CacheDistributionMode.NEAR_ONLY) - return; - loadAll(cache, ImmutableSet.of(key1, key2), true); - assert cache.localPeek(key1, CachePeekMode.ONHEAP) == 1; - assert cache.localPeek(key2, CachePeekMode.ONHEAP) == 2; - assert cache.localPeek(key3, CachePeekMode.ONHEAP) == 3; + CacheAffinity aff = ignite(0).affinity(null); + + for (int i = 0; i < gridCount(); i++) { + if (aff.isPrimaryOrBackup(grid(i).cluster().localNode(), key1)) + assertEquals((Integer)1, peek(jcache(i), key1)); + + if (aff.isPrimaryOrBackup(grid(i).cluster().localNode(), key2)) + assertEquals((Integer)2, peek(jcache(i), key2)); + + if (aff.isPrimaryOrBackup(grid(i).cluster().localNode(), key3)) + assertEquals((Integer)3, peek(jcache(i), key3)); + } } /** diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java index ff645410442c5..7268c93b8b07d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java @@ -253,7 +253,6 @@ protected CacheConfiguration cacheConfiguration(String gridName) throws Exceptio cfg.setAtomicityMode(atomicityMode()); cfg.setWriteSynchronizationMode(writeSynchronization()); cfg.setDistributionMode(distributionMode()); - cfg.setPortableEnabled(portableEnabled()); if (cacheMode() == PARTITIONED) cfg.setBackups(1); @@ -342,13 +341,6 @@ protected boolean lockingEnabled() { return true; } - /** - * @return Whether portable mode is enabled. - */ - protected boolean portableEnabled() { - return false; - } - /** * @return {@code True} for partitioned caches. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityMapperSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityMapperSelfTest.java index 89baa85344a30..060491ae9d4f7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityMapperSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityMapperSelfTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.processors.cache; import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.junits.common.*; import java.util.*; @@ -26,6 +27,16 @@ * Test affinity mapper. */ public class GridCacheAffinityMapperSelfTest extends GridCommonAbstractTest { + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrid(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + /** * */ @@ -33,6 +44,8 @@ public void testMethodAffinityMapper() { CacheAffinityKeyMapper mapper = new GridCacheDefaultAffinityKeyMapper(); + GridTestUtils.setFieldValue(mapper, "ignite", grid()); + List> keys = new ArrayList<>(); for (int i = 1; i <= 10; i++) @@ -57,6 +70,8 @@ public void testFieldAffinityMapper() { CacheAffinityKeyMapper mapper = new GridCacheDefaultAffinityKeyMapper(); + GridTestUtils.setFieldValue(mapper, "ignite", grid()); + List> keys = new ArrayList<>(); for (int i = 1; i <= 10; i++) @@ -81,6 +96,8 @@ public void testFieldAffinityMapperWithWrongClass() { CacheAffinityKeyMapper mapper = new GridCacheDefaultAffinityKeyMapper(); + GridTestUtils.setFieldValue(mapper, "ignite", grid()); + FieldNoAffinityKey key = new FieldNoAffinityKey(); Object mapped = mapper.affinityKey(key); assertEquals(key, mapped); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicMessageCountSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicMessageCountSelfTest.java index e6a911bbc920f..325a16934e1ad 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicMessageCountSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicMessageCountSelfTest.java @@ -23,7 +23,7 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.spi.discovery.tcp.*; @@ -194,7 +194,7 @@ private static class TestCommunicationSpi extends TcpCommunicationSpi { private Map, AtomicInteger> cntMap = new HashMap<>(); /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { AtomicInteger cntr = cntMap.get(((GridIoMessage)msg).message().getClass()); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMemoryModeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMemoryModeSelfTest.java index c1a84c32e6ce9..842468bfeea2d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMemoryModeSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMemoryModeSelfTest.java @@ -87,7 +87,6 @@ public class GridCacheMemoryModeSelfTest extends GridCommonAbstractTest { cacheCfg.setAtomicityMode(atomicity); cacheCfg.setOffHeapMaxMemory(offheapSize); cacheCfg.setQueryIndexEnabled(memoryMode != CacheMemoryMode.OFFHEAP_VALUES); - cacheCfg.setPortableEnabled(portableEnabled()); cfg.setCacheConfiguration(cacheCfg); cfg.setMarshaller(new OptimizedMarshaller(false)); @@ -95,13 +94,6 @@ public class GridCacheMemoryModeSelfTest extends GridCommonAbstractTest { return cfg; } - /** - * @return Portable enabled flag. - */ - protected boolean portableEnabled() { - return false; - } - /** * @throws Exception If failed. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapMultiThreadedUpdateAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapMultiThreadedUpdateAbstractSelfTest.java index df2fb564c36fb..541061a6e7963 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapMultiThreadedUpdateAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapMultiThreadedUpdateAbstractSelfTest.java @@ -58,7 +58,6 @@ public abstract class GridCacheOffHeapMultiThreadedUpdateAbstractSelfTest extend ccfg.setOffHeapMaxMemory(1024 * 1024); ccfg.setWriteSynchronizationMode(FULL_SYNC); ccfg.setAtomicWriteOrderMode(PRIMARY); - ccfg.setPortableEnabled(portableEnabled()); return ccfg; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredAbstractSelfTest.java index a9ba172fec2d6..78ad52ae82ebf 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredAbstractSelfTest.java @@ -21,7 +21,6 @@ import org.apache.ignite.cache.*; import org.apache.ignite.configuration.*; import org.apache.ignite.lang.*; -import org.apache.ignite.portables.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; import org.junit.*; @@ -59,18 +58,8 @@ public abstract class GridCacheOffHeapTieredAbstractSelfTest extends GridCacheAb } /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - if (portableEnabled()) { - PortableConfiguration pCfg = new PortableConfiguration(); - - pCfg.setClassNames(Arrays.asList(TestValue.class.getName())); - - cfg.setPortableConfiguration(pCfg); - } - - return cfg; + protected boolean portableEnabled() { + return false; } /** {@inheritDoc} */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java index ae3599d51f8be..787793d2829fe 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java @@ -22,7 +22,6 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.portables.*; import org.apache.ignite.testframework.*; import javax.cache.*; @@ -61,21 +60,6 @@ public abstract class GridCacheOffHeapTieredEvictionAbstractSelfTest extends Gri return 60 * 1000; } - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - if (portableEnabled()) { - PortableConfiguration pCfg = new PortableConfiguration(); - - pCfg.setClassNames(Arrays.asList(TestValue.class.getName())); - - cfg.setPortableConfiguration(pCfg); - } - - return cfg; - } - /** {@inheritDoc} */ @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { CacheConfiguration ccfg = super.cacheConfiguration(gridName); @@ -208,10 +192,8 @@ public void testTransform() throws Exception { * @param acceptNull If {@code true} value can be null; * @return Predicate. */ - private TestPredicate testPredicate(String expVal, boolean acceptNull) { - return portableEnabled() ? - new PortableValuePredicate(expVal, acceptNull) : - new TestValuePredicate(expVal, acceptNull); + protected TestPredicate testPredicate(String expVal, boolean acceptNull) { + return new TestValuePredicate(expVal, acceptNull); } /** @@ -219,10 +201,8 @@ private TestPredicate testPredicate(String expVal, boolean acceptNull) { * @param acceptNull If {@code true} value can be null; * @return Predicate. */ - private TestProcessor testClosure(String expVal, boolean acceptNull) { - return portableEnabled() ? - new PortableValueClosure(expVal, acceptNull) : - new TestValueClosure(expVal, acceptNull); + protected TestProcessor testClosure(String expVal, boolean acceptNull) { + return new TestValueClosure(expVal, acceptNull); } /** @@ -289,28 +269,7 @@ protected TestPredicate(String expVal, boolean acceptNull) { /** * @param val Value. */ - abstract void checkValue(Object val); - } - - /** - * - */ - @SuppressWarnings("PackageVisibleInnerClass") - static class PortableValuePredicate extends TestPredicate { - /** - * @param expVal Expected value. - * @param acceptNull If {@code true} value can be null; - */ - PortableValuePredicate(String expVal, boolean acceptNull) { - super(expVal, acceptNull); - } - - /** {@inheritDoc} */ - @Override void checkValue(Object val) { - PortableObject obj = (PortableObject)val; - - assertEquals(expVal, obj.field("val")); - } + public abstract void checkValue(Object val); } /** @@ -327,7 +286,7 @@ static class TestValuePredicate extends TestPredicate { } /** {@inheritDoc} */ - @Override void checkValue(Object val) { + @Override public void checkValue(Object val) { TestValue obj = (TestValue)val; assertEquals(expVal, obj.val); @@ -376,28 +335,7 @@ protected TestProcessor(String expVal, boolean acceptNull) { /** * @param val Value. */ - abstract void checkValue(Object val); - } - - /** - * - */ - @SuppressWarnings("PackageVisibleInnerClass") - static class PortableValueClosure extends TestProcessor { - /** - * @param expVal Expected value. - * @param acceptNull If {@code true} value can be null; - */ - PortableValueClosure(String expVal, boolean acceptNull) { - super(expVal, acceptNull); - } - - /** {@inheritDoc} */ - @Override void checkValue(Object val) { - PortableObject obj = (PortableObject)val; - - assertEquals(expVal, obj.field("val")); - } + public abstract void checkValue(Object val); } /** @@ -414,7 +352,7 @@ static class TestValueClosure extends TestProcessor { } /** {@inheritDoc} */ - @Override void checkValue(Object val) { + @Override public void checkValue(Object val) { TestValue obj = (TestValue)val; assertEquals(expVal, obj.val); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedSynchronousCommitTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedSynchronousCommitTest.java index d37eab5ba4f9f..85ba6ce07d2a3 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedSynchronousCommitTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedSynchronousCommitTest.java @@ -24,7 +24,7 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.cache.distributed.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.spi.discovery.tcp.*; @@ -185,7 +185,7 @@ public int messagesCount() { } /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { Object obj = ((GridIoMessage)msg).message(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractTest.java index f704a7553a8f9..0a4596eaf76b1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractTest.java @@ -121,7 +121,6 @@ protected CacheConfiguration cacheConfiguration(String gridName) throws Exceptio cfg.setWriteSynchronizationMode(writeSynchronization()); cfg.setDistributionMode(distributionMode()); - cfg.setPortableEnabled(portableEnabled()); cfg.setCacheLoaderFactory(loaderFactory()); @@ -198,13 +197,6 @@ protected CacheWriteSynchronizationMode writeSynchronization() { return FULL_SYNC; } - /** - * @return Whether portable mode is enabled. - */ - protected boolean portableEnabled() { - return false; - } - /** * @return {@code true} if swap should be enabled. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekModesTest.java similarity index 93% rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekModesTest.java index 4c3eb6a2205e0..024774b7d19d0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekModesTest.java @@ -25,7 +25,7 @@ /** * */ -public class IgniteCacheAtomicLocalPeekTest extends IgniteCachePeekAbstractTest { +public class IgniteCacheAtomicLocalPeekModesTest extends IgniteCachePeekModesAbstractTest { /** {@inheritDoc} */ @Override protected CacheAtomicityMode atomicityMode() { return ATOMIC; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekModesTest.java similarity index 94% rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekModesTest.java index c2085ecaf6fdd..bf595f004a87c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekModesTest.java @@ -26,7 +26,7 @@ /** * */ -public class IgniteCacheAtomicPeekTest extends IgniteCachePeekAbstractTest { +public class IgniteCacheAtomicPeekModesTest extends IgniteCachePeekModesAbstractTest { /** {@inheritDoc} */ @Override protected int gridCount() { return 4; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekModesTest.java similarity index 91% rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekModesTest.java index 3b0f0f6939e0f..7286ba301eead 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekModesTest.java @@ -24,7 +24,7 @@ /** * */ -public class IgniteCacheTxReplicatedPeekTest extends IgniteCacheTxPeekTest { +public class IgniteCacheAtomicReplicatedPeekModesTest extends IgniteCacheAtomicPeekModesTest { /** {@inheritDoc} */ @Override protected CacheMode cacheMode() { return REPLICATED; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java deleted file mode 100644 index 006cb8b572dcd..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.affinity.*; -import org.apache.ignite.cache.eviction.fifo.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.spi.*; -import org.apache.ignite.spi.swapspace.inmemory.*; - -import java.util.*; - -import static org.apache.ignite.cache.CacheDistributionMode.*; -import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.CachePeekMode.*; - -/** - * - */ -public abstract class IgniteCachePeekAbstractTest extends IgniteCacheAbstractTest { - /** */ - private static final int HEAP_ENTRIES = 10; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setSwapSpaceSpi(new GridTestSwapSpaceSpi()); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected CacheDistributionMode distributionMode() { - return PARTITIONED_ONLY; - } - - /** {@inheritDoc} */ - @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { - CacheConfiguration ccfg = super.cacheConfiguration(gridName); - - ccfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED); - - ccfg.setOffHeapMaxMemory(512); - - ccfg.setBackups(1); - - if (gridName.equals(getTestGridName(0))) - ccfg.setDistributionMode(NEAR_PARTITIONED); - - ccfg.setEvictionPolicy(new CacheFifoEvictionPolicy(HEAP_ENTRIES)); - - return ccfg; - } - - /** {@inheritDoc} */ - @Override protected boolean swapEnabled() { - return true; - } - - /** - * @throws Exception If failed. - */ - public void testLocalPeek() throws Exception { - if (cacheMode() == LOCAL) { - checkAffinityLocalCache(); - - checkStorage(0); - } - else { - checkAffinityPeek(0); - - checkAffinityPeek(1); - - checkStorage(0); - - checkStorage(1); - } - } - - /** - * @throws Exception If failed. - */ - private void checkAffinityLocalCache() throws Exception { - IgniteCache cache0 = jcache(0); - - final String val = "1"; - - for (int i = 0; i < HEAP_ENTRIES; i++) - cache0.put(i, val); - - try { - for (int i = 0; i < HEAP_ENTRIES; i++) { - assertEquals(val, cache0.localPeek(i)); - assertEquals(val, cache0.localPeek(i, ALL)); - assertEquals(val, cache0.localPeek(i, PRIMARY)); - assertEquals(val, cache0.localPeek(i, BACKUP)); - assertEquals(val, cache0.localPeek(i, NEAR)); - } - } - finally { - for (int i = 0; i < HEAP_ENTRIES; i++) - cache0.remove(i); - } - } - - /** - * @param nodeIdx Node index. - * @throws Exception If failed. - */ - private void checkAffinityPeek(int nodeIdx) throws Exception { - IgniteCache cache0 = jcache(nodeIdx); - - final String val = "1"; - - Integer key = null; - - try { - if (cacheMode() == REPLICATED) { - key = backupKey(cache0); - - cache0.put(key, val); - - assertEquals(val, cache0.localPeek(key, ALL)); - assertEquals(val, cache0.localPeek(key, BACKUP)); - assertNull(cache0.localPeek(key, NEAR)); - assertNull(cache0.localPeek(key, PRIMARY)); - } - else { - key = nearKey(cache0); - - cache0.put(key, val); - - boolean hasNearCache = nodeIdx == 0 ; - - if (hasNearCache) { - assertEquals(val, cache0.localPeek(key, NEAR)); - assertEquals(val, cache0.localPeek(key, ALL)); - } - else { - assertNull(cache0.localPeek(key, NEAR)); - assertNull(cache0.localPeek(key, ALL)); - } - - assertNull(cache0.localPeek(key, PRIMARY)); - assertNull(cache0.localPeek(key, BACKUP)); - } - - CacheAffinity aff = ignite(0).affinity(null); - - for (int i = 0; i < gridCount(); i++) { - if (i == nodeIdx) - continue; - - IgniteCache cache = jcache(i); - - assertNull(cache.localPeek(key, NEAR)); - - if (aff.isPrimary(ignite(i).cluster().localNode(), key)) { - assertEquals(val, cache.localPeek(key, PRIMARY)); - assertEquals(val, cache.localPeek(key, ALL)); - assertNull(cache.localPeek(key, BACKUP)); - assertNull(cache.localPeek(key, NEAR)); - } - else if (aff.isBackup(ignite(i).cluster().localNode(), key)) { - assertEquals(val, cache.localPeek(key, BACKUP)); - assertEquals(val, cache.localPeek(key, ALL)); - assertNull(cache.localPeek(key, PRIMARY)); - assertNull(cache.localPeek(key, NEAR)); - } - else { - assertNull(cache.localPeek(key, ALL)); - assertNull(cache.localPeek(key, PRIMARY)); - assertNull(cache.localPeek(key, BACKUP)); - assertNull(cache.localPeek(key, NEAR)); - } - } - } - finally { - if (key != null) - cache0.remove(key); - } - } - - /** - * @param nodeIdx Node index. - * @throws Exception If failed. - */ - private void checkStorage(int nodeIdx) throws Exception { - IgniteCache cache0 = jcache(nodeIdx); - - List keys = primaryKeys(cache0, 100, 10_000); - - try { - final String val = "test_value"; - - for (Integer key : keys) - cache0.put(key, val); - - GridTestSwapSpaceSpi swap = (GridTestSwapSpaceSpi)ignite(nodeIdx).configuration().getSwapSpaceSpi(); - - Set swapKeys = new HashSet<>(); - - final String spaceName = "gg-swap-cache-dflt"; - - IgniteSpiCloseableIterator it = swap.keyIterator(spaceName, null); - - assertNotNull(it); - - while (it.hasNext()) - assertTrue(swapKeys.add(it.next())); - - assertFalse(swapKeys.isEmpty()); - - assertTrue(swapKeys.size() + HEAP_ENTRIES < 100); - - Set offheapKeys = new HashSet<>(); - - GridCacheAdapter internalCache = - ((IgniteKernal)ignite(nodeIdx)).context().cache().internalCache(); - - Iterator> offheapIt; - - if (internalCache.context().isNear()) - offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator(); - else - offheapIt = internalCache.context().swap().lazyOffHeapIterator(); - - while (offheapIt.hasNext()) { - Map.Entry e = offheapIt.next(); - - assertTrue(offheapKeys.add(e.getKey())); - - assertFalse(swapKeys.contains(e.getKey())); - } - - assertFalse(offheapKeys.isEmpty()); - - Set heapKeys = new HashSet<>(keys); - - heapKeys.removeAll(offheapKeys); - heapKeys.removeAll(swapKeys); - - assertFalse(heapKeys.isEmpty()); - - log.info("Keys [swap=" + swapKeys.size() + - ", offheap=" + offheapKeys.size() + - ", heap=" + heapKeys.size() + ']'); - - assertEquals(100, swapKeys.size() + offheapKeys.size() + heapKeys.size()); - - for (Integer key : swapKeys) { - assertEquals(val, cache0.localPeek(key, SWAP)); - assertEquals(val, cache0.localPeek(key, PRIMARY, SWAP)); - assertEquals(val, cache0.localPeek(key, ONHEAP, SWAP)); - assertEquals(val, cache0.localPeek(key, ONHEAP, OFFHEAP, SWAP)); - assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP, SWAP)); - assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP, OFFHEAP, SWAP)); - - if (cacheMode() == LOCAL) { - assertEquals(val, cache0.localPeek(key, SWAP, BACKUP)); - assertEquals(val, cache0.localPeek(key, SWAP, NEAR)); - } - else { - assertNull(cache0.localPeek(key, SWAP, BACKUP)); - assertNull(cache0.localPeek(key, SWAP, NEAR)); - } - - assertNull(cache0.localPeek(key, ONHEAP)); - assertNull(cache0.localPeek(key, OFFHEAP)); - } - - for (Integer key : offheapKeys) { - assertEquals(val, cache0.localPeek(key, OFFHEAP)); - assertEquals(val, cache0.localPeek(key, ONHEAP, OFFHEAP)); - assertEquals(val, cache0.localPeek(key, ONHEAP, SWAP, OFFHEAP)); - assertEquals(val, cache0.localPeek(key, PRIMARY, OFFHEAP)); - - if (cacheMode() == LOCAL) { - assertEquals(val, cache0.localPeek(key, OFFHEAP, BACKUP)); - assertEquals(val, cache0.localPeek(key, OFFHEAP, NEAR)); - } - else { - assertNull(cache0.localPeek(key, OFFHEAP, BACKUP)); - assertNull(cache0.localPeek(key, OFFHEAP, NEAR)); - } - - assertNull(cache0.localPeek(key, ONHEAP)); - assertNull(cache0.localPeek(key, SWAP)); - } - - for (Integer key : heapKeys) { - assertEquals(val, cache0.localPeek(key, ONHEAP)); - assertEquals(val, cache0.localPeek(key, SWAP, ONHEAP)); - assertEquals(val, cache0.localPeek(key, SWAP, OFFHEAP, ONHEAP)); - assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP)); - - if (cacheMode() == LOCAL) { - assertEquals(val, cache0.localPeek(key, ONHEAP, BACKUP)); - assertEquals(val, cache0.localPeek(key, ONHEAP, NEAR)); - } - else { - assertNull(cache0.localPeek(key, ONHEAP, BACKUP)); - assertNull(cache0.localPeek(key, ONHEAP, NEAR)); - } - - assertNull(cache0.localPeek(key, SWAP)); - assertNull(cache0.localPeek(key, OFFHEAP)); - } - } - finally { - cache0.removeAll(new HashSet<>(keys)); - } - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java new file mode 100644 index 0000000000000..96cc9af8cc380 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java @@ -0,0 +1,1131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cache.eviction.fifo.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.spi.*; +import org.apache.ignite.spi.swapspace.file.*; + +import javax.cache.*; +import java.util.*; + +import static org.apache.ignite.cache.CacheDistributionMode.*; +import static org.apache.ignite.cache.CacheMode.*; +import static org.apache.ignite.cache.CachePeekMode.*; + +/** + * Tests for methods using {@link CachePeekMode}: + *

        + *
      • {@link IgniteCache#localPeek(Object, CachePeekMode...)}
      • + *
      • {@link IgniteCache#localSize(CachePeekMode...)}
      • + *
      • {@link IgniteCache#size(CachePeekMode...)}
      • + *
      • {@link IgniteCache#localEntries(CachePeekMode...)}
      • + *
      + */ +public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstractTest { + /** */ + private static final String SPACE_NAME = "gg-swap-cache-dflt"; + + /** */ + private static final int HEAP_ENTRIES = 30; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setSwapSpaceSpi(new FileSwapSpaceSpi()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected CacheDistributionMode distributionMode() { + return PARTITIONED_ONLY; + } + + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(gridName); + + ccfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED); + + ccfg.setOffHeapMaxMemory(512); + + ccfg.setBackups(1); + + if (gridName.equals(getTestGridName(0))) + ccfg.setDistributionMode(NEAR_PARTITIONED); + + ccfg.setEvictionPolicy(new CacheFifoEvictionPolicy(HEAP_ENTRIES)); + + return ccfg; + } + + /** {@inheritDoc} */ + @Override protected boolean swapEnabled() { + return true; + } + + /** + * @throws Exception If failed. + */ + public void testLocalPeek() throws Exception { + if (cacheMode() == LOCAL) { + checkAffinityLocalCache(); + + checkStorage(0); + } + else { + checkAffinityPeek(0); + + checkAffinityPeek(1); + + checkStorage(0); + + checkStorage(1); + } + } + + /** + * @throws Exception If failed. + */ + private void checkAffinityLocalCache() throws Exception { + IgniteCache cache0 = jcache(0); + + final String val = "1"; + + for (int i = 0; i < HEAP_ENTRIES; i++) + cache0.put(i, val); + + try { + for (int i = 0; i < HEAP_ENTRIES; i++) { + assertEquals(val, cache0.localPeek(i)); + assertEquals(val, cache0.localPeek(i, ALL)); + assertEquals(val, cache0.localPeek(i, PRIMARY)); + assertEquals(val, cache0.localPeek(i, BACKUP)); + assertEquals(val, cache0.localPeek(i, NEAR)); + } + } + finally { + for (int i = 0; i < HEAP_ENTRIES; i++) + cache0.remove(i); + } + } + + /** + * @param nodeIdx Node index. + * @throws Exception If failed. + */ + private void checkAffinityPeek(int nodeIdx) throws Exception { + IgniteCache cache0 = jcache(nodeIdx); + + final String val = "1"; + + Integer key = null; + + try { + if (cacheMode() == REPLICATED) { + key = backupKey(cache0); + + cache0.put(key, val); + + assertEquals(val, cache0.localPeek(key, ALL)); + assertEquals(val, cache0.localPeek(key, BACKUP)); + assertNull(cache0.localPeek(key, NEAR)); + assertNull(cache0.localPeek(key, PRIMARY)); + } + else { + key = nearKey(cache0); + + cache0.put(key, val); + + boolean hasNearCache = nodeIdx == 0 ; + + if (hasNearCache) { + assertEquals(val, cache0.localPeek(key, NEAR)); + assertEquals(val, cache0.localPeek(key, ALL)); + } + else { + assertNull(cache0.localPeek(key, NEAR)); + assertNull(cache0.localPeek(key, ALL)); + } + + assertNull(cache0.localPeek(key, PRIMARY)); + assertNull(cache0.localPeek(key, BACKUP)); + } + + CacheAffinity aff = ignite(0).affinity(null); + + for (int i = 0; i < gridCount(); i++) { + if (i == nodeIdx) + continue; + + IgniteCache cache = jcache(i); + + assertNull(cache.localPeek(key, NEAR)); + + if (aff.isPrimary(ignite(i).cluster().localNode(), key)) { + assertEquals(val, cache.localPeek(key, PRIMARY)); + assertEquals(val, cache.localPeek(key, ALL)); + assertNull(cache.localPeek(key, BACKUP)); + assertNull(cache.localPeek(key, NEAR)); + } + else if (aff.isBackup(ignite(i).cluster().localNode(), key)) { + assertEquals(val, cache.localPeek(key, BACKUP)); + assertEquals(val, cache.localPeek(key, ALL)); + assertNull(cache.localPeek(key, PRIMARY)); + assertNull(cache.localPeek(key, NEAR)); + } + else { + assertNull(cache.localPeek(key, ALL)); + assertNull(cache.localPeek(key, PRIMARY)); + assertNull(cache.localPeek(key, BACKUP)); + assertNull(cache.localPeek(key, NEAR)); + } + } + } + finally { + if (key != null) + cache0.remove(key); + } + } + + /** + * @param nodeIdx Node index. + * @throws Exception If failed. + */ + private void checkStorage(int nodeIdx) throws Exception { + IgniteCache cache0 = jcache(nodeIdx); + + List keys = primaryKeys(cache0, 100, 10_000); + + try { + final String val = "test_value"; + + for (Integer key : keys) + cache0.put(key, val); + + FileSwapSpaceSpi swap = (FileSwapSpaceSpi)ignite(nodeIdx).configuration().getSwapSpaceSpi(); + + Set swapKeys = new HashSet<>(); + + IgniteSpiCloseableIterator it = swap.keyIterator(SPACE_NAME, null); + + assertNotNull(it); + + while (it.hasNext()) + assertTrue(swapKeys.add(it.next())); + + assertFalse(swapKeys.isEmpty()); + + assertTrue(swapKeys.size() + HEAP_ENTRIES < 100); + + Set offheapKeys = new HashSet<>(); + + GridCacheAdapter internalCache = + ((IgniteKernal)ignite(nodeIdx)).context().cache().internalCache(); + + Iterator> offheapIt; + + if (internalCache.context().isNear()) + offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator(); + else + offheapIt = internalCache.context().swap().lazyOffHeapIterator(); + + while (offheapIt.hasNext()) { + Map.Entry e = offheapIt.next(); + + assertTrue(offheapKeys.add(e.getKey())); + + assertFalse(swapKeys.contains(e.getKey())); + } + + assertFalse(offheapKeys.isEmpty()); + + Set heapKeys = new HashSet<>(keys); + + heapKeys.removeAll(offheapKeys); + heapKeys.removeAll(swapKeys); + + assertFalse(heapKeys.isEmpty()); + + log.info("Keys [swap=" + swapKeys.size() + + ", offheap=" + offheapKeys.size() + + ", heap=" + heapKeys.size() + ']'); + + assertEquals(100, swapKeys.size() + offheapKeys.size() + heapKeys.size()); + + for (Integer key : swapKeys) { + assertEquals(val, cache0.localPeek(key, SWAP)); + assertEquals(val, cache0.localPeek(key, PRIMARY, SWAP)); + assertEquals(val, cache0.localPeek(key, ONHEAP, SWAP)); + assertEquals(val, cache0.localPeek(key, ONHEAP, OFFHEAP, SWAP)); + assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP, SWAP)); + assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP, OFFHEAP, SWAP)); + + if (cacheMode() == LOCAL) { + assertEquals(val, cache0.localPeek(key, SWAP, BACKUP)); + assertEquals(val, cache0.localPeek(key, SWAP, NEAR)); + } + else { + assertNull(cache0.localPeek(key, SWAP, BACKUP)); + assertNull(cache0.localPeek(key, SWAP, NEAR)); + } + + assertNull(cache0.localPeek(key, ONHEAP)); + assertNull(cache0.localPeek(key, OFFHEAP)); + } + + for (Integer key : offheapKeys) { + assertEquals(val, cache0.localPeek(key, OFFHEAP)); + assertEquals(val, cache0.localPeek(key, ONHEAP, OFFHEAP)); + assertEquals(val, cache0.localPeek(key, ONHEAP, SWAP, OFFHEAP)); + assertEquals(val, cache0.localPeek(key, PRIMARY, OFFHEAP)); + + if (cacheMode() == LOCAL) { + assertEquals(val, cache0.localPeek(key, OFFHEAP, BACKUP)); + assertEquals(val, cache0.localPeek(key, OFFHEAP, NEAR)); + } + else { + assertNull(cache0.localPeek(key, OFFHEAP, BACKUP)); + assertNull(cache0.localPeek(key, OFFHEAP, NEAR)); + } + + assertNull(cache0.localPeek(key, ONHEAP)); + assertNull(cache0.localPeek(key, SWAP)); + } + + for (Integer key : heapKeys) { + assertEquals(val, cache0.localPeek(key, ONHEAP)); + assertEquals(val, cache0.localPeek(key, SWAP, ONHEAP)); + assertEquals(val, cache0.localPeek(key, SWAP, OFFHEAP, ONHEAP)); + assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP)); + + if (cacheMode() == LOCAL) { + assertEquals(val, cache0.localPeek(key, ONHEAP, BACKUP)); + assertEquals(val, cache0.localPeek(key, ONHEAP, NEAR)); + } + else { + assertNull(cache0.localPeek(key, ONHEAP, BACKUP)); + assertNull(cache0.localPeek(key, ONHEAP, NEAR)); + } + + assertNull(cache0.localPeek(key, SWAP)); + assertNull(cache0.localPeek(key, OFFHEAP)); + } + } + finally { + cache0.removeAll(new HashSet<>(keys)); + } + } + + /** + * @throws Exception If failed. + */ + public void testSize() throws Exception { + checkEmpty(); + + if (cacheMode() == LOCAL) { + IgniteCache cache0 = jcache(0); + + IgniteCache cacheAsync0 = cache0.withAsync(); + + for (int i = 0; i < HEAP_ENTRIES; i++) { + cache0.put(i, String.valueOf(i)); + + final int size = i + 1; + + assertEquals(size, cache0.localSize()); + assertEquals(size, cache0.localSize(PRIMARY)); + assertEquals(size, cache0.localSize(BACKUP)); + assertEquals(size, cache0.localSize(NEAR)); + assertEquals(size, cache0.localSize(ALL)); + + assertEquals(size, cache0.size()); + assertEquals(size, cache0.size(PRIMARY)); + assertEquals(size, cache0.size(BACKUP)); + assertEquals(size, cache0.size(NEAR)); + assertEquals(size, cache0.size(ALL)); + + cacheAsync0.size(); + + assertEquals(size, cacheAsync0.future().get()); + + cacheAsync0.size(PRIMARY); + + assertEquals(size, cacheAsync0.future().get()); + } + + for (int i = 0; i < HEAP_ENTRIES; i++) { + cache0.remove(i, String.valueOf(i)); + + final int size = HEAP_ENTRIES - i - 1; + + assertEquals(size, cache0.localSize()); + assertEquals(size, cache0.localSize(PRIMARY)); + assertEquals(size, cache0.localSize(BACKUP)); + assertEquals(size, cache0.localSize(NEAR)); + assertEquals(size, cache0.localSize(ALL)); + + assertEquals(size, cache0.size()); + assertEquals(size, cache0.size(PRIMARY)); + assertEquals(size, cache0.size(BACKUP)); + assertEquals(size, cache0.size(NEAR)); + assertEquals(size, cache0.size(ALL)); + + cacheAsync0.size(); + + assertEquals(size, cacheAsync0.future().get()); + } + + checkEmpty(); + + Set keys = new HashSet<>(); + + for (int i = 0; i < 200; i++) { + cache0.put(i, "test_val"); + + keys.add(i); + } + + try { + int totalKeys = 200; + + T2 swapKeys = swapKeysCount(0); + + T2 offheapKeys = offheapKeysCount(0); + + int totalSwap = swapKeys.get1() + swapKeys.get2(); + int totalOffheap = offheapKeys.get1() + offheapKeys.get2(); + + log.info("Keys [total=" + totalKeys + ", offheap=" + offheapKeys + ", swap=" + swapKeys + ']'); + + assertTrue(totalSwap + totalOffheap < totalKeys); + + assertEquals(totalKeys, cache0.localSize()); + assertEquals(totalKeys, cache0.localSize(ALL)); + + assertEquals(totalOffheap, cache0.localSize(OFFHEAP)); + assertEquals(totalSwap, cache0.localSize(SWAP)); + assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSize(ONHEAP)); + + assertEquals(totalOffheap, cache0.size(OFFHEAP)); + assertEquals(totalSwap, cache0.size(SWAP)); + assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.size(ONHEAP)); + + assertEquals(totalOffheap, cache0.localSize(OFFHEAP, PRIMARY)); + assertEquals(totalSwap, cache0.localSize(SWAP, PRIMARY)); + assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSize(ONHEAP, PRIMARY)); + + assertEquals(totalOffheap, cache0.localSize(OFFHEAP, BACKUP)); + assertEquals(totalSwap, cache0.localSize(SWAP, BACKUP)); + assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSize(ONHEAP, BACKUP)); + } + finally { + cache0.removeAll(keys); + } + } + else { + checkSizeAffinityFilter(0); + + checkSizeAffinityFilter(1); + + checkSizeStorageFilter(0); + + checkSizeStorageFilter(1); + } + } + + /** + * @param nodeIdx Node index. + * @throws Exception If failed. + */ + private void checkSizeAffinityFilter(int nodeIdx) throws Exception { + IgniteCache cache0 = jcache(nodeIdx); + + final int PUT_KEYS = 10; + + List keys = null; + + try { + if (cacheMode() == REPLICATED) { + keys = backupKeys(cache0, 10, 0); + + for (Integer key : keys) + cache0.put(key, String.valueOf(key)); + + assertEquals(PUT_KEYS, cache0.localSize()); + assertEquals(PUT_KEYS, cache0.localSize(BACKUP)); + assertEquals(PUT_KEYS, cache0.localSize(ALL)); + assertEquals(0, cache0.localSize(PRIMARY)); + assertEquals(0, cache0.localSize(NEAR)); + + for (int i = 0; i < gridCount(); i++) { + IgniteCache cache = jcache(i); + + assertEquals(0, cache.size(NEAR)); + assertEquals(PUT_KEYS, cache.size(PRIMARY)); + assertEquals(PUT_KEYS * (gridCount() - 1), cache.size(BACKUP)); + assertEquals(PUT_KEYS * gridCount(), cache.size(PRIMARY, BACKUP)); + assertEquals(PUT_KEYS * gridCount(), cache.size()); // Primary + backups. + } + } + else { + keys = nearKeys(cache0, PUT_KEYS, 0); + + for (Integer key : keys) + cache0.put(key, String.valueOf(key)); + + boolean hasNearCache = nodeIdx == 0 ; + + if (hasNearCache) { + assertEquals(PUT_KEYS, cache0.localSize()); + assertEquals(PUT_KEYS, cache0.localSize(ALL)); + assertEquals(PUT_KEYS, cache0.localSize(NEAR)); + + for (int i = 0; i < gridCount(); i++) { + IgniteCache cache = jcache(i); + + assertEquals(PUT_KEYS, cache.size(NEAR)); + assertEquals(PUT_KEYS, cache.size(BACKUP)); + assertEquals(PUT_KEYS * 2, cache.size(PRIMARY, BACKUP)); + assertEquals(PUT_KEYS * 2 + PUT_KEYS, cache.size()); // Primary + backups + near. + } + } + else { + assertEquals(0, cache0.localSize()); + assertEquals(0, cache0.localSize(ALL)); + assertEquals(0, cache0.localSize(NEAR)); + + for (int i = 0; i < gridCount(); i++) { + IgniteCache cache = jcache(i); + + assertEquals(0, cache.size(NEAR)); + assertEquals(PUT_KEYS, cache.size(BACKUP)); + assertEquals(PUT_KEYS * 2, cache.size(PRIMARY, BACKUP)); + assertEquals(PUT_KEYS * 2, cache.size()); // Primary + backups. + } + } + + assertEquals(0, cache0.localSize(BACKUP)); + assertEquals(0, cache0.localSize(PRIMARY)); + } + + checkPrimarySize(PUT_KEYS); + + CacheAffinity aff = ignite(0).affinity(null); + + for (int i = 0; i < gridCount(); i++) { + if (i == nodeIdx) + continue; + + ClusterNode node = ignite(i).cluster().localNode(); + + int primary = 0; + int backups = 0; + + for (Integer key : keys) { + if (aff.isPrimary(node, key)) + primary++; + else if (aff.isBackup(node, key)) + backups++; + } + + IgniteCache cache = jcache(i); + + assertEquals(primary, cache.localSize(PRIMARY)); + assertEquals(backups, cache.localSize(BACKUP)); + assertEquals(primary + backups, cache.localSize(PRIMARY, BACKUP)); + assertEquals(primary + backups, cache.localSize(BACKUP, PRIMARY)); + assertEquals(primary + backups, cache.localSize(ALL)); + } + + cache0.remove(keys.get(0)); + + checkPrimarySize(PUT_KEYS - 1); + + if (cacheMode() == REPLICATED) { + assertEquals(PUT_KEYS - 1, cache0.localSize()); + assertEquals(0, cache0.localSize(PRIMARY)); + assertEquals(PUT_KEYS - 1, cache0.localSize(BACKUP)); + } + else { + boolean hasNearCache = nodeIdx == 0; + + if (hasNearCache) + assertEquals(PUT_KEYS - 1, cache0.localSize()); + else + assertEquals(0, cache0.localSize()); + } + } + finally { + if (keys != null) + cache0.removeAll(new HashSet<>(keys)); + } + + checkEmpty(); + } + + /** + * Checks size is zero. + */ + private void checkEmpty() { + for (int i = 0; i < gridCount(); i++) { + IgniteCache cache = jcache(i); + + assertEquals(0, cache.localSize()); + + assertEquals(0, cache.size()); + + for (CachePeekMode peekMode : CachePeekMode.values()) { + assertEquals(0, cache.localSize(peekMode)); + + assertEquals(0, cache.size(peekMode)); + } + } + + checkPrimarySize(0); + } + + /** + * @param nodeIdx Node index. + * @return Tuple with primary and backup keys. + */ + private T2, List> swapKeys(int nodeIdx) { + FileSwapSpaceSpi swap = (FileSwapSpaceSpi)ignite(nodeIdx).configuration().getSwapSpaceSpi(); + + IgniteSpiCloseableIterator it = swap.keyIterator(SPACE_NAME, null); + + assertNotNull(it); + + CacheAffinity aff = ignite(nodeIdx).affinity(null); + + ClusterNode node = ignite(nodeIdx).cluster().localNode(); + + List primary = new ArrayList<>(); + List backups = new ArrayList<>(); + + while (it.hasNext()) { + Integer key = it.next(); + + if (aff.isPrimary(node, key)) + primary.add(key); + else { + assertTrue(aff.isBackup(node, key)); + + backups.add(key); + } + } + + return new T2<>(primary, backups); + } + + /** + * @param nodeIdx Node index. + * @return Tuple with number of primary and backup keys. + */ + private T2 swapKeysCount(int nodeIdx) { + T2, List> keys = swapKeys(nodeIdx); + + return new T2<>(keys.get1().size(), keys.get2().size()); + } + + /** + * @param nodeIdx Node index. + * @return Tuple with primary and backup keys. + */ + private T2, List> offheapKeys(int nodeIdx) { + GridCacheAdapter internalCache = + ((IgniteKernal)ignite(nodeIdx)).context().cache().internalCache(); + + Iterator> offheapIt; + + if (internalCache.context().isNear()) + offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator(); + else + offheapIt = internalCache.context().swap().lazyOffHeapIterator(); + + CacheAffinity aff = ignite(nodeIdx).affinity(null); + + ClusterNode node = ignite(nodeIdx).cluster().localNode(); + + List primary = new ArrayList<>(); + List backups = new ArrayList<>(); + + while (offheapIt.hasNext()) { + Map.Entry e = offheapIt.next(); + + if (aff.isPrimary(node, e.getKey())) + primary.add(e.getKey()); + else { + assertTrue(aff.isBackup(node, e.getKey())); + + backups.add(e.getKey()); + } + } + + return new T2<>(primary, backups); + } + + /** + * @param nodeIdx Node index. + * @return Tuple with number of primary and backup keys. + */ + private T2 offheapKeysCount(int nodeIdx) { + T2, List> keys = offheapKeys(nodeIdx); + + return new T2<>(keys.get1().size(), keys.get2().size()); + } + + /** + * @param nodeIdx Node index. + * @throws Exception If failed. + */ + private void checkSizeStorageFilter(int nodeIdx) throws Exception { + IgniteCache cache0 = jcache(nodeIdx); + + List primaryKeys = primaryKeys(cache0, 100, 10_000); + List backupKeys = backupKeys(cache0, 100, 10_000); + + try { + final String val = "test_value"; + + for (int i = 0; i < 100; i++) { + cache0.put(primaryKeys.get(i), val); + cache0.put(backupKeys.get(i), val); + } + + int totalKeys = 200; + + T2 swapKeys = swapKeysCount(nodeIdx); + + assertTrue(swapKeys.get1() > 0); + assertTrue(swapKeys.get2() > 0); + + T2 offheapKeys = offheapKeysCount(nodeIdx); + + assertTrue(offheapKeys.get1() > 0); + assertTrue(offheapKeys.get2() > 0); + + int totalSwap = swapKeys.get1() + swapKeys.get2(); + int totalOffheap = offheapKeys.get1() + offheapKeys.get2(); + + log.info("Local keys [total=" + totalKeys + ", offheap=" + offheapKeys + ", swap=" + swapKeys + ']'); + + assertTrue(totalSwap + totalOffheap < totalKeys); + + assertEquals(totalKeys, cache0.localSize()); + assertEquals(totalKeys, cache0.localSize(ALL)); + assertEquals(totalOffheap, cache0.localSize(OFFHEAP)); + assertEquals(totalSwap, cache0.localSize(SWAP)); + assertEquals(totalKeys - (totalOffheap + totalSwap), cache0.localSize(ONHEAP)); + assertEquals(totalKeys, cache0.localSize(SWAP, OFFHEAP, ONHEAP)); + + assertEquals(swapKeys.get1(), (Integer)cache0.localSize(SWAP, PRIMARY)); + assertEquals(swapKeys.get2(), (Integer)cache0.localSize(SWAP, BACKUP)); + + assertEquals(offheapKeys.get1(), (Integer)cache0.localSize(OFFHEAP, PRIMARY)); + assertEquals(offheapKeys.get2(), (Integer)cache0.localSize(OFFHEAP, BACKUP)); + + assertEquals(swapKeys.get1() + offheapKeys.get1(), cache0.localSize(SWAP, OFFHEAP, PRIMARY)); + assertEquals(swapKeys.get2() + offheapKeys.get2(), cache0.localSize(SWAP, OFFHEAP, BACKUP)); + + assertEquals(totalSwap + totalOffheap, cache0.localSize(SWAP, OFFHEAP)); + + int globalSwapPrimary = 0; + int globalSwapBackup = 0; + + int globalOffheapPrimary = 0; + int globalOffheapBackup = 0; + + for (int i = 0; i < gridCount(); i++) { + T2 swap = swapKeysCount(i); + + globalSwapPrimary += swap.get1(); + globalSwapBackup += swap.get2(); + + T2 offheap = offheapKeysCount(i); + + globalOffheapPrimary += offheap.get1(); + globalOffheapBackup += offheap.get2(); + } + + int backups; + + if (cacheMode() == LOCAL) + backups = 0; + else if (cacheMode() == PARTITIONED) + backups = 1; + else // REPLICATED. + backups = gridCount() - 1; + + int globalTotal = totalKeys + totalKeys * backups; + int globalTotalSwap = globalSwapPrimary + globalSwapBackup; + int globalTotalOffheap = globalOffheapPrimary + globalOffheapBackup; + + log.info("Global keys [total=" + globalTotal + + ", offheap=" + globalTotalOffheap + + ", swap=" + globalTotalSwap + ']'); + + for (int i = 0; i < gridCount(); i++) { + IgniteCache cache = jcache(i); + + assertEquals(globalTotal, cache.size()); + assertEquals(globalTotal, cache.size(ALL)); + assertEquals(globalTotal, cache.size(ONHEAP, OFFHEAP, SWAP)); + assertEquals(globalTotal, cache.size(ONHEAP, OFFHEAP, SWAP, PRIMARY, BACKUP)); + + assertEquals(globalTotalSwap, cache.size(SWAP)); + assertEquals(globalSwapPrimary, cache.size(SWAP, PRIMARY)); + assertEquals(globalSwapBackup, cache.size(SWAP, BACKUP)); + + assertEquals(globalTotalOffheap, cache.size(OFFHEAP)); + assertEquals(globalOffheapPrimary, cache.size(OFFHEAP, PRIMARY)); + assertEquals(globalOffheapBackup, cache.size(OFFHEAP, BACKUP)); + + assertEquals(globalTotalSwap + globalTotalOffheap, cache.size(SWAP, OFFHEAP)); + assertEquals(globalSwapPrimary + globalOffheapPrimary, cache.size(SWAP, OFFHEAP, PRIMARY)); + assertEquals(globalSwapBackup + globalOffheapBackup, cache.size(SWAP, OFFHEAP, BACKUP)); + + assertEquals(globalTotal - (globalTotalOffheap + globalTotalSwap), cache.size(ONHEAP)); + } + } + finally { + cache0.removeAll(new HashSet<>(primaryKeys)); + cache0.removeAll(new HashSet<>(backupKeys)); + } + + checkEmpty(); + } + + /** + * @param exp Expected size. + */ + private void checkPrimarySize(int exp) { + int size = 0; + + for (int i = 0; i < gridCount(); i++) { + IgniteCache cache = jcache(i); + + IgniteCache cacheAsync = cache.withAsync(); + + assertEquals(exp, cache.size(PRIMARY)); + + size += cache.localSize(PRIMARY); + + cacheAsync.size(PRIMARY); + + assertEquals(exp, cacheAsync.future().get()); + } + + assertEquals(exp, size); + } + + /** + * @throws Exception If failed. + */ + public void testLocalEntries() throws Exception { + if (cacheMode() == LOCAL) { + IgniteCache cache0 = jcache(0); + + Set keys = new HashSet<>(); + + try { + for (int i = 0; i < HEAP_ENTRIES; i++) { + cache0.put(i, String.valueOf(i)); + + keys.add(i); + } + + checkLocalEntries(cache0.localEntries(), keys); + checkLocalEntries(cache0.localEntries(ALL), keys); + checkLocalEntries(cache0.localEntries(NEAR), keys); + checkLocalEntries(cache0.localEntries(PRIMARY), keys); + checkLocalEntries(cache0.localEntries(BACKUP), keys); + } + finally { + cache0.removeAll(keys); + } + + checkLocalEntries(cache0.localEntries()); + + final String val = "test-val-"; + + keys = new HashSet<>(); + + for (int i = 0; i < 200; i++) { + cache0.put(i, val + i); + + keys.add(i); + } + + try { + int totalKeys = 200; + + T2, List> swapKeys = swapKeys(0); + + T2, List> offheapKeys = offheapKeys(0); + + List swap = new ArrayList<>(); + + swap.addAll(swapKeys.get1()); + swap.addAll(swapKeys.get2()); + + assertFalse(swap.isEmpty()); + + List offheap = new ArrayList<>(); + + offheap.addAll(offheapKeys.get1()); + offheap.addAll(offheapKeys.get2()); + + assertFalse(offheap.isEmpty()); + + log.info("Keys [total=" + totalKeys + + ", offheap=" + offheap.size() + + ", swap=" + swap.size() + ']'); + + assertTrue(swap.size() + offheap.size() < totalKeys); + + List heap = new ArrayList<>(keys); + + heap.removeAll(swap); + heap.removeAll(offheap); + + assertFalse(heap.isEmpty()); + + checkLocalEntries(cache0.localEntries(), val, keys); + checkLocalEntries(cache0.localEntries(ALL), val, keys); + + checkLocalEntries(cache0.localEntries(OFFHEAP), val, offheap); + checkLocalEntries(cache0.localEntries(SWAP), val, swap); + checkLocalEntries(cache0.localEntries(ONHEAP), val, heap); + + checkLocalEntries(cache0.localEntries(OFFHEAP, PRIMARY), val, offheap); + checkLocalEntries(cache0.localEntries(SWAP, PRIMARY), val, swap); + checkLocalEntries(cache0.localEntries(ONHEAP, PRIMARY), val, heap); + + checkLocalEntries(cache0.localEntries(OFFHEAP, BACKUP), val, offheap); + checkLocalEntries(cache0.localEntries(SWAP, BACKUP), val, swap); + checkLocalEntries(cache0.localEntries(ONHEAP, BACKUP), val, heap); + + checkLocalEntries(cache0.localEntries(OFFHEAP, NEAR), val, offheap); + checkLocalEntries(cache0.localEntries(SWAP, NEAR), val, swap); + checkLocalEntries(cache0.localEntries(ONHEAP, NEAR), val, heap); + } + finally { + cache0.removeAll(keys); + } + } + else { + checkLocalEntriesAffinityFilter(0); + + checkLocalEntriesAffinityFilter(1); + + checkLocalEntriesStorageFilter(0); + + checkLocalEntriesStorageFilter(1); + } + } + + /** + * @param nodeIdx Node index. + * @throws Exception If failed. + */ + private void checkLocalEntriesStorageFilter(int nodeIdx) throws Exception { + IgniteCache cache0 = jcache(nodeIdx); + + List primaryKeys = primaryKeys(cache0, 100, 10_000); + List backupKeys = backupKeys(cache0, 100, 10_000); + + try { + final String val = "test_value-"; + + for (int i = 0; i < 100; i++) { + cache0.put(primaryKeys.get(i), val + primaryKeys.get(i)); + cache0.put(backupKeys.get(i), val + backupKeys.get(i)); + } + + int totalKeys = 200; + + T2, List> swapKeys = swapKeys(nodeIdx); + + assertTrue(swapKeys.get1().size() > 0); + assertTrue(swapKeys.get2().size() > 0); + + T2, List> offheapKeys = offheapKeys(nodeIdx); + + assertTrue(offheapKeys.get1().size() > 0); + assertTrue(offheapKeys.get2().size() > 0); + + List swap = new ArrayList<>(); + + swap.addAll(swapKeys.get1()); + swap.addAll(swapKeys.get2()); + + assertFalse(swap.isEmpty()); + + List offheap = new ArrayList<>(); + + offheap.addAll(offheapKeys.get1()); + offheap.addAll(offheapKeys.get2()); + + assertFalse(offheap.isEmpty()); + + List heap = new ArrayList<>(); + + heap.addAll(primaryKeys); + heap.addAll(backupKeys); + + heap.removeAll(swap); + heap.removeAll(offheap); + + log.info("Keys [total=" + totalKeys + + ", offheap=" + offheap.size() + + ", swap=" + swap.size() + ']'); + + assertFalse(heap.isEmpty()); + + checkLocalEntries(cache0.localEntries(), val, primaryKeys, backupKeys); + checkLocalEntries(cache0.localEntries(ALL), val, primaryKeys, backupKeys); + checkLocalEntries(cache0.localEntries(ONHEAP, OFFHEAP, SWAP), val, primaryKeys, backupKeys); + + checkLocalEntries(cache0.localEntries(SWAP), val, swap); + checkLocalEntries(cache0.localEntries(OFFHEAP), val, offheap); + checkLocalEntries(cache0.localEntries(ONHEAP), val, heap); + + checkLocalEntries(cache0.localEntries(SWAP, OFFHEAP), val, swap, offheap); + checkLocalEntries(cache0.localEntries(SWAP, ONHEAP), val, swap, heap); + + checkLocalEntries(cache0.localEntries(SWAP, PRIMARY), val, swapKeys.get1()); + checkLocalEntries(cache0.localEntries(SWAP, BACKUP), val, swapKeys.get2()); + checkLocalEntries(cache0.localEntries(OFFHEAP, PRIMARY), val, offheapKeys.get1()); + checkLocalEntries(cache0.localEntries(OFFHEAP, BACKUP), val, offheapKeys.get2()); + + checkLocalEntries(cache0.localEntries(SWAP, OFFHEAP, PRIMARY), val, swapKeys.get1(), offheapKeys.get1()); + checkLocalEntries(cache0.localEntries(SWAP, OFFHEAP, BACKUP), val, swapKeys.get2(), offheapKeys.get2()); + checkLocalEntries(cache0.localEntries(SWAP, OFFHEAP, PRIMARY, BACKUP), val, swap, offheap); + } + finally { + cache0.removeAll(new HashSet<>(primaryKeys)); + cache0.removeAll(new HashSet<>(backupKeys)); + } + } + + /** + * @param nodeIdx Node index. + * @throws Exception If failed. + */ + private void checkLocalEntriesAffinityFilter(int nodeIdx) throws Exception { + IgniteCache cache0 = jcache(nodeIdx); + + final int PUT_KEYS = 10; + + List primaryKeys = null; + List backupKeys = null; + List nearKeys = null; + + try { + primaryKeys = primaryKeys(cache0, PUT_KEYS, 0); + backupKeys = backupKeys(cache0, PUT_KEYS, 0); + + for (Integer key : primaryKeys) + cache0.put(key, String.valueOf(key)); + for (Integer key : backupKeys) + cache0.put(key, String.valueOf(key)); + + nearKeys = cacheMode() == PARTITIONED ? nearKeys(cache0, PUT_KEYS, 0) : Collections.emptyList(); + + for (Integer key : nearKeys) + cache0.put(key, String.valueOf(key)); + + log.info("Keys [near=" + nearKeys + ", primary=" + primaryKeys + ", backup=" + backupKeys + ']'); + + boolean hasNearCache = nodeIdx == 0 && cacheMode() == PARTITIONED; + + if (hasNearCache) { + checkLocalEntries(cache0.localEntries(), nearKeys, primaryKeys, backupKeys); + checkLocalEntries(cache0.localEntries(ALL), nearKeys, primaryKeys, backupKeys); + checkLocalEntries(cache0.localEntries(NEAR), nearKeys); + checkLocalEntries(cache0.localEntries(PRIMARY, BACKUP, NEAR), nearKeys, primaryKeys, backupKeys); + checkLocalEntries(cache0.localEntries(NEAR, PRIMARY), nearKeys, primaryKeys); + checkLocalEntries(cache0.localEntries(NEAR, BACKUP), nearKeys, backupKeys); + } + else { + checkLocalEntries(cache0.localEntries(), primaryKeys, backupKeys); + checkLocalEntries(cache0.localEntries(ALL), primaryKeys, backupKeys); + checkLocalEntries(cache0.localEntries(NEAR)); + checkLocalEntries(cache0.localEntries(NEAR, PRIMARY), primaryKeys); + checkLocalEntries(cache0.localEntries(NEAR, BACKUP), backupKeys); + checkLocalEntries(cache0.localEntries(PRIMARY, BACKUP, NEAR), primaryKeys, backupKeys); + } + + checkLocalEntries(cache0.localEntries(PRIMARY), primaryKeys); + checkLocalEntries(cache0.localEntries(BACKUP), backupKeys); + checkLocalEntries(cache0.localEntries(PRIMARY, BACKUP), primaryKeys, backupKeys); + } + finally { + if (primaryKeys != null) + cache0.removeAll(new HashSet<>(primaryKeys)); + + if (backupKeys != null) + cache0.removeAll(new HashSet<>(backupKeys)); + + if (nearKeys != null) + cache0.removeAll(new HashSet<>(nearKeys)); + } + } + + /** + * @param entries Entries. + * @param exp Expected entries. + */ + private void checkLocalEntries(Iterable> entries, Collection... exp) { + checkLocalEntries(entries, "", exp); + } + + /** + * @param entries Entries. + * @param expVal Expected value. + * @param exp Expected keys. + */ + private void checkLocalEntries(Iterable> entries, + String expVal, + Collection... exp) { + Set allExp = new HashSet<>(); + + for (Collection col : exp) + assertTrue(allExp.addAll(col)); + + for (Cache.Entry e : entries) { + assertNotNull(e.getKey()); + assertNotNull(e.getValue()); + assertEquals(expVal + e.getKey(), e.getValue()); + + assertTrue("Unexpected entry: " + e, allExp.remove(e.getKey())); + } + + assertTrue("Expected entries not found: " + allExp, allExp.isEmpty()); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekModesTest.java similarity index 93% rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekModesTest.java index f4b70cfb85941..234d5013e8ea0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekModesTest.java @@ -25,7 +25,7 @@ /** * */ -public class IgniteCacheTxLocalPeekTest extends IgniteCachePeekAbstractTest { +public class IgniteCacheTxLocalPeekModesTest extends IgniteCachePeekModesAbstractTest { /** {@inheritDoc} */ @Override protected CacheAtomicityMode atomicityMode() { return TRANSACTIONAL; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekModesTest.java similarity index 94% rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekModesTest.java index 0ddeaaf107d5a..08a2c7d777ff2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekModesTest.java @@ -26,7 +26,7 @@ /** * */ -public class IgniteCacheTxPeekTest extends IgniteCachePeekAbstractTest { +public class IgniteCacheTxPeekModesTest extends IgniteCachePeekModesAbstractTest { /** {@inheritDoc} */ @Override protected int gridCount() { return 4; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekModesTest.java similarity index 92% rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekModesTest.java index 4d348274f8fea..616ca3a10f064 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekModesTest.java @@ -24,7 +24,7 @@ /** * */ -public class IgniteCacheAtomicReplicatedPeekTest extends IgniteCacheAtomicPeekTest { +public class IgniteCacheTxReplicatedPeekModesTest extends IgniteCacheTxPeekModesTest { /** {@inheritDoc} */ @Override protected CacheMode cacheMode() { return REPLICATED; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxReentryAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxReentryAbstractSelfTest.java index 254cf5aac1225..2442c8b2d77da 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxReentryAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxReentryAbstractSelfTest.java @@ -24,7 +24,7 @@ import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.distributed.dht.*; import org.apache.ignite.internal.processors.cache.distributed.near.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.spi.discovery.tcp.*; @@ -134,7 +134,7 @@ protected static class CountingCommunicationSpi extends TcpCommunicationSpi { private AtomicInteger dhtLocks = new AtomicInteger(); /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { countMsg((GridIoMessage)msg); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java index dfcf6ab0510c7..e5fdc132ed004 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java @@ -68,13 +68,6 @@ public abstract class GridCacheAbstractDistributedByteArrayValuesSelfTest extend */ protected abstract boolean peerClassLoading(); - /** - * @return Whether portable mode is enabled. - */ - protected boolean portableEnabled() { - return false; - } - /** * @return How many grids to start. */ @@ -89,7 +82,6 @@ protected CacheConfiguration cacheConfiguration() { CacheConfiguration cfg = cacheConfiguration0(); cfg.setName(CACHE_REGULAR); - cfg.setPortableEnabled(portableEnabled()); return cfg; } @@ -106,7 +98,6 @@ protected CacheConfiguration offheapCacheConfiguration() { CacheConfiguration cfg = offheapCacheConfiguration0(); cfg.setName(CACHE_OFFHEAP); - cfg.setPortableEnabled(portableEnabled()); return cfg; } @@ -118,7 +109,6 @@ protected CacheConfiguration offheapTieredCacheConfiguration() { CacheConfiguration cfg = offheapTieredCacheConfiguration0(); cfg.setName(CACHE_OFFHEAP_TIERED); - cfg.setPortableEnabled(portableEnabled()); return cfg; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractPartitionedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractPartitionedByteArrayValuesSelfTest.java index c5fadafa5a4f8..485f95ca8e47c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractPartitionedByteArrayValuesSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractPartitionedByteArrayValuesSelfTest.java @@ -54,7 +54,6 @@ public abstract class GridCacheAbstractPartitionedByteArrayValuesSelfTest extend cfg.setSwapEnabled(true); cfg.setEvictSynchronized(false); cfg.setEvictNearSynchronized(false); - cfg.setPortableEnabled(portableEnabled()); return cfg; } @@ -71,7 +70,6 @@ public abstract class GridCacheAbstractPartitionedByteArrayValuesSelfTest extend cfg.setMemoryMode(OFFHEAP_VALUES); cfg.setOffHeapMaxMemory(100 * 1024 * 1024); cfg.setQueryIndexEnabled(false); - cfg.setPortableEnabled(portableEnabled()); return cfg; } @@ -88,7 +86,6 @@ public abstract class GridCacheAbstractPartitionedByteArrayValuesSelfTest extend cfg.setMemoryMode(OFFHEAP_TIERED); cfg.setOffHeapMaxMemory(100 * 1024 * 1024); cfg.setQueryIndexEnabled(false); - cfg.setPortableEnabled(portableEnabled()); return cfg; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAtomicTimeoutSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAtomicTimeoutSelfTest.java index 6d62a84a189bf..55d1068e1dd3f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAtomicTimeoutSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAtomicTimeoutSelfTest.java @@ -26,10 +26,10 @@ import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.testframework.*; @@ -274,7 +274,7 @@ private static class TestCommunicationSpi extends TcpCommunicationSpi { private boolean skipDhtResponse; /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { if (!skipMessage((GridIoMessage)msg)) super.sendMessage(node, msg); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java index 7c860e105626f..f6931794a59b6 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java @@ -25,10 +25,10 @@ import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.transactions.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.resources.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; @@ -239,7 +239,7 @@ protected void testTxOriginatingNodeFails(Collection keys, final boolea IgniteConfiguration cfg = super.getConfiguration(gridName); cfg.setCommunicationSpi(new TcpCommunicationSpi() { - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { if (!F.eq(ignoreMsgNodeId, node.id()) || !ignoredMessage((GridIoMessage)msg)) super.sendMessage(node, msg); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest.java index e4bda2585fa56..9568789f41278 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest.java @@ -26,10 +26,10 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.near.*; import org.apache.ignite.internal.processors.cache.transactions.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.resources.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; @@ -418,7 +418,7 @@ private Collection allNodeIds() { IgniteConfiguration cfg = super.getConfiguration(gridName); cfg.setCommunicationSpi(new TcpCommunicationSpi() { - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { if (getSpiContext().localNode().id().equals(failingNodeId)) { if (ignoredMessage((GridIoMessage)msg) && ignoreMsgNodeIds != null) { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java index 0b4f0487102ee..cbbaeeb240c26 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java @@ -23,6 +23,7 @@ import org.apache.ignite.internal.processors.cache.distributed.near.*; import org.apache.ignite.testframework.*; +import javax.cache.*; import java.util.*; import java.util.concurrent.*; @@ -70,6 +71,23 @@ protected CacheAtomicWriteOrderMode atomicWriteOrderMode() { return ccfg; } + /** + * @throws Exception If failed. + */ + public void testLock() throws Exception { + GridTestUtils.assertThrows(log, new Callable() { + @Override public Object call() throws Exception { + return jcache().lock("1").tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS); + } + }, CacheException.class, "Locks are not supported"); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Object call() throws Exception { + return jcache().lockAll(Collections.singleton("1")).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS); + } + }, CacheException.class, "Locks are not supported"); + } + /** * @throws Exception In case of error. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadMessageCountTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadMessageCountTest.java index 53987013ffc26..e621847db6f55 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadMessageCountTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadMessageCountTest.java @@ -24,8 +24,8 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.spi.discovery.tcp.*; @@ -141,7 +141,7 @@ private static class TestCommunicationSpi extends TcpCommunicationSpi { private Collection sentMsgs = new ConcurrentLinkedQueue<>(); /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { recordMessage((GridIoMessage)msg); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicInvalidPartitionHandlingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicInvalidPartitionHandlingSelfTest.java index 1e83921ff22bc..9fc882eceedd0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicInvalidPartitionHandlingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicInvalidPartitionHandlingSelfTest.java @@ -24,8 +24,8 @@ import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.spi.discovery.tcp.*; @@ -296,7 +296,7 @@ private void checkRestarts(CacheAtomicWriteOrderMode writeOrder, CacheWriteSynch */ private static class DelayCommunicationSpi extends TcpCommunicationSpi { /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode node, MessageAdapter msg) throws IgniteSpiException { try { if (delayMessage((GridIoMessage)msg)) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java index 17aa98c3b0800..843a1caf1941b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java @@ -71,6 +71,16 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends GridCache return PARTITIONED_ONLY; } + /** {@inheritDoc} */ + @Override public void testReaderTtlNoTx() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testReaderTtlTx() throws Exception { + // No-op. + } + /** {@inheritDoc} */ @Override public void testSize() throws Exception { IgniteCache cache = jcache(); @@ -134,8 +144,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends GridCache } /** {@inheritDoc} */ - // TODO: IGNITE-206: Enable when fixed. - @Override public void _testEvictExpired() throws Exception { + @Override public void testEvictExpired() throws Exception { IgniteCache cache = jcache(); String key = primaryKeysForCache(cache, 1).get(0); @@ -175,8 +184,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends GridCache } /** {@inheritDoc} */ - // TODO: IGNITE-206: Enable when fixed. - @Override public void _testLocalEvict() throws Exception { + @Override public void testLocalEvict() throws Exception { IgniteCache cache = jcache(); List keys = primaryKeysForCache(cache, 3); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java index ca698816502f4..59a347f473490 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java @@ -19,8 +19,8 @@ import org.apache.ignite.*; import org.apache.ignite.cache.*; +import org.apache.ignite.cache.affinity.*; import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.typedef.*; import javax.cache.expiry.*; import java.util.*; @@ -68,6 +68,7 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends GridCacheNe return PARTITIONED_ONLY; } + /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { for (int i = 0; i < gridCount(); i++) grid(i).cache(null).removeAll(); @@ -111,12 +112,10 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends GridCacheNe for (String key : keys) assertEquals((Integer)i++, nearCache.localPeek(key, CachePeekMode.ONHEAP)); - } /** {@inheritDoc} */ - // TODO: IGNITE-206: Enable when fixed. - @Override public void _testEvictExpired() throws Exception { + @Override public void testEvictExpired() throws Exception { IgniteCache cache = jcache(); String key = primaryKeysForCache(cache, 1).get(0); @@ -143,15 +142,13 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends GridCacheNe assertTrue(cache.localSize() == 0); - // Force reload on primary node. - for (int i = 0; i < gridCount(); i++) { - if (ignite(i).affinity(null).isPrimary(ignite(i).cluster().localNode(), key)) - load(jcache(i), key, true); - } - - // Will do near get request. load(cache, key, true); - assertEquals((Integer)1, cache.localPeek(key, CachePeekMode.ONHEAP)); + CacheAffinity aff = ignite(0).affinity(null); + + for (int i = 0; i < gridCount(); i++) { + if (aff.isPrimaryOrBackup(grid(i).cluster().localNode(), key)) + assertEquals((Integer)1, peek(jcache(i), key)); + } } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java index bc83d152beed1..2c2e0757c7db1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java @@ -24,15 +24,20 @@ import org.apache.ignite.events.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.transactions.*; +import javax.cache.expiry.*; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*; import static org.apache.ignite.cache.CacheDistributionMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; @@ -98,7 +103,7 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio GridCacheAttributes[] nodeAttrs = node.attribute(IgniteNodeAttributes.ATTR_CACHE); - info("Cache attribtues for node [nodeId=" + node.id() + ", attrs=" + + info("Cache attributes for node [nodeId=" + node.id() + ", attrs=" + Arrays.asList(nodeAttrs) + ']'); } @@ -183,6 +188,186 @@ protected IgniteCache fullCache() { // TODO fix this test for client mode. } + /** + * @throws Exception If failed. + */ + public void testReaderTtlTx() throws Exception { + checkReaderTtl(true); + } + + /** + * @throws Exception If failed. + */ + public void testReaderTtlNoTx() throws Exception { + checkReaderTtl(false); + } + + /** + * + * @throws Exception + */ + private void checkReaderTtl(boolean inTx) throws Exception { + int ttl = 1000; + + final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl)); + + final GridCache c = cache(); + + final String key = primaryKeysForCache(jcache(), 1).get(0); + + c.put(key, 1); + + CacheEntry entry = c.entry(key); + + assert entry != null; + + assertEquals(0, entry.timeToLive()); + assertEquals(0, entry.expirationTime()); + + long startTime = System.currentTimeMillis(); + + int fullIdx = nearIdx == 0 ? 1 : 0; + + // Now commit transaction and check that ttl and expire time have been saved. + IgniteTx tx = inTx ? grid(fullIdx).transactions().txStart() : null; + + try { + jcache(fullIdx).withExpiryPolicy(expiry).put(key, 1); + + if (tx != null) + tx.commit(); + } + finally { + if (tx != null) + tx.close(); + } + + long[] expireTimes = new long[gridCount()]; + + for (int i = 0; i < gridCount(); i++) { + CacheEntry curEntry = cache(i).entry(key); + + if (curEntry.primary() || curEntry.backup() || i == nearIdx) { + assertEquals(ttl, curEntry.timeToLive()); + + assert curEntry.expirationTime() > startTime; + + expireTimes[i] = curEntry.expirationTime(); + } + } + + // One more update from the same cache entry to ensure that expire time is shifted forward. + U.sleep(100); + + tx = inTx ? grid(fullIdx).transactions().txStart() : null; + + try { + jcache(fullIdx).withExpiryPolicy(expiry).put(key, 2); + + if (tx != null) + tx.commit(); + } + finally { + if (tx != null) + tx.close(); + } + + for (int i = 0; i < gridCount(); i++) { + CacheEntry curEntry = cache(i).entry(key); + + if (curEntry.primary() || curEntry.backup() || i == nearIdx) { + assertEquals(ttl, curEntry.timeToLive()); + + assert curEntry.expirationTime() > expireTimes[i]; + + expireTimes[i] = curEntry.expirationTime(); + } + } + + // And one more update to ensure that ttl is not changed and expire time is not shifted forward. + U.sleep(100); + + tx = inTx ? grid(fullIdx).transactions().txStart() : null; + + try { + jcache(fullIdx).put(key, 4); + } + finally { + if (tx != null) + tx.commit(); + } + + for (int i = 0; i < gridCount(); i++) { + CacheEntry curEntry = cache(i).entry(key); + + if (curEntry.primary() || curEntry.backup() || i == nearIdx) { + assertEquals(ttl, curEntry.timeToLive()); + assertEquals(expireTimes[i], curEntry.expirationTime()); + } + } + + // Avoid reloading from store. + map.remove(key); + + assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() { + @SuppressWarnings("unchecked") + @Override public boolean applyx() throws IgniteCheckedException { + try { + Integer val = c.get(key); + + if (val != null) { + info("Value is in cache [key=" + key + ", val=" + val + ']'); + + return false; + } + + // Get "cache" field from GridCacheProxyImpl. + GridCacheAdapter c0 = GridTestUtils.getFieldValue(c, "cache"); + + if (!c0.context().deferredDelete()) { + GridCacheEntryEx e0 = c0.peekEx(key); + + return e0 == null || (e0.rawGet() == null && e0.valueBytes() == null); + } + else + return true; + } + catch (GridCacheEntryRemovedException e) { + throw new RuntimeException(e); + } + } + }, Math.min(ttl * 10, getTestTimeout()))); + + // Ensure that old TTL and expire time are not longer "visible". + entry = c.entry(key); + + assert entry.get() == null; + + assertEquals(0, entry.timeToLive()); + assertEquals(0, entry.expirationTime()); + + // Ensure that next update will not pick old expire time. + + tx = inTx ? c.txStart() : null; + + try { + entry.set(10); + } + finally { + if (tx != null) + tx.commit(); + } + + U.sleep(2000); + + entry = c.entry(key); + + assertEquals((Integer)10, entry.get()); + + assertEquals(0, entry.timeToLive()); + assertEquals(0, entry.expirationTime()); + } + /** {@inheritDoc} */ @Override public void testClear() throws Exception { IgniteCache nearCache = jcache(); @@ -235,20 +420,35 @@ protected IgniteCache fullCache() { } } - /** {@inheritDoc} */ - @Override public void testGlobalClearAll() throws Exception { + /** + * @param async If {@code true} uses async method. + * @throws Exception If failed. + */ + @Override protected void globalClearAll(boolean async) throws Exception { // Save entries only on their primary nodes. If we didn't do so, clearLocally() will not remove all entries // because some of them were blocked due to having readers. for (int i = 0; i < gridCount(); i++) { - if (i != nearIdx) - for (String key : primaryKeysForCache(jcache(i), 3)) + if (i != nearIdx) { + for (String key : primaryKeysForCache(jcache(i), 3, 100_000)) jcache(i).put(key, 1); + } } - jcache().clear(); + if (async) { + IgniteCache asyncCache = jcache(nearIdx).withAsync(); - for (int i = 0; i < gridCount(); i++) - assertTrue(String.valueOf(jcache(i)), jcache(i).localSize() == 0); + asyncCache.clear(); + + asyncCache.future().get(); + } + else + jcache(nearIdx).clear(); + + for (int i = 0; i < gridCount(); i++) { + assertEquals("Unexpected size [node=" + ignite(i).name() + ", nearIdx=" + nearIdx + ']', + 0, + jcache(i).localSize()); + } } /** {@inheritDoc} */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java index 5a79a5bdc9ada..04934ce660337 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java @@ -17,19 +17,12 @@ package org.apache.ignite.internal.processors.cache.distributed.near; -import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.*; import org.apache.log4j.*; -import javax.cache.*; -import java.util.*; -import java.util.concurrent.*; - import static org.apache.ignite.cache.CacheMode.*; /** @@ -56,31 +49,4 @@ public class GridCachePartitionedLockSelfTest extends GridCacheLockAbstractTest @Override protected boolean isPartitioned() { return true; } - - /** - * @throws IgniteCheckedException If failed. - */ - public void testLockAtomicCache() throws Exception { - IgniteConfiguration cfg = new IgniteConfiguration(); - - cfg.setGridName(getTestGridName(0)); - cfg.setClientConnectionConfiguration(null); - cfg.setCacheConfiguration(new CacheConfiguration()); - - final Ignite g0 = G.start(cfg); - - final IgniteCache cache = g0.jcache(null); - - GridTestUtils.assertThrows(log, new Callable() { - @Override public Object call() throws Exception { - return cache.lock(1).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS); - } - }, CacheException.class, "Locks are not supported"); - - GridTestUtils.assertThrows(log, new Callable() { - @Override public Object call() throws Exception { - return cache.lockAll(Collections.singleton(1)).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS); - } - }, CacheException.class, "Locks are not supported"); - } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedInvalidateSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedInvalidateSelfTest.java index cfd1b877fc519..5d8545f563c61 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedInvalidateSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedInvalidateSelfTest.java @@ -24,7 +24,7 @@ import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.clock.*; import org.apache.ignite.internal.transactions.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.spi.discovery.tcp.*; @@ -224,7 +224,7 @@ public void clearCounts() { } /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode destNode, GridTcpCommunicationMessageAdapter msg) + @Override public void sendMessage(ClusterNode destNode, MessageAdapter msg) throws IgniteSpiException { Object msg0 = ((GridIoMessage)msg).message(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheSwapScanQueryAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheSwapScanQueryAbstractSelfTest.java index 1f26666037739..2aa3264290cf1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheSwapScanQueryAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheSwapScanQueryAbstractSelfTest.java @@ -22,7 +22,6 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.optimized.*; -import org.apache.ignite.portables.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; @@ -69,14 +68,6 @@ public abstract class GridCacheSwapScanQueryAbstractSelfTest extends GridCommonA cfg.setCacheConfiguration(cacheConfiguration(ATOMIC_CACHE_NAME, ATOMIC), cacheConfiguration(TRANSACTIONAL_CACHE_NAME, TRANSACTIONAL)); - if (portableEnabled()) { - PortableConfiguration pCfg = new PortableConfiguration(); - - pCfg.setClassNames(Arrays.asList(Key.class.getName(), Person.class.getName())); - - cfg.setPortableConfiguration(pCfg); - } - return cfg; } @@ -102,18 +93,11 @@ private CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode at ccfg.setAtomicWriteOrderMode(PRIMARY); - ccfg.setPortableEnabled(portableEnabled()); - ccfg.setWriteSynchronizationMode(FULL_SYNC); return ccfg; } - /** - * @return Portable enabled flag. - */ - protected abstract boolean portableEnabled(); - /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGrids(4); @@ -183,6 +167,49 @@ private void checkQuery(GridCache cache) throws Exception { } } + /** + * @param cache Cache. + * @param expCnt Expected entries in query result. + * @throws Exception If failed. + */ + @SuppressWarnings({"unchecked", "IfMayBeConditional"}) + private void checkProjectionFilter(GridCache cache, int expCnt) throws Exception { + CacheProjection prj = createProjectionForFilter(cache); + + CacheQuery> qry = prj.queries().createScanQuery( + new IgniteBiPredicate() { + @Override public boolean apply(Key key, Person p) { + assertEquals(key.id, (Integer)p.salary); + + return key.id % 2 == 0; + } + } + ); + + Collection> res = qry.execute().get(); + + assertEquals(expCnt, res.size()); + } + + /** + * @param cache Cache. + * @return Projection. + */ + protected CacheProjection createProjectionForFilter(GridCache cache) { + return cache.projection(new IgnitePredicate>() { + @Override public boolean apply(CacheEntry e) { + Key key = e.getKey(); + Person val = e.peek(); + + assertNotNull(e.version()); + + assertEquals(key.id, (Integer)val.salary); + + return key.id % 100 != 0; + } + }); + } + /** * @param cache Cache. * @param expCnt Expected entries in query result. diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheSwapScanQuerySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheSwapScanQuerySelfTest.java index c15cd5beae716..61f921ceef5e5 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheSwapScanQuerySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheSwapScanQuerySelfTest.java @@ -21,8 +21,4 @@ * */ public class GridCacheSwapScanQuerySelfTest extends GridCacheSwapScanQueryAbstractSelfTest { - /** {@inheritDoc} */ - @Override protected boolean portableEnabled() { - return false; - } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java index fd0b8b015c239..8ec97f90facb5 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java @@ -148,10 +148,10 @@ public void testInsert() throws Exception { assertTrue("Failed to insert for index: " + i, map.contains(hash(key), key.getBytes())); assertEquals(val, new String(map.get(hash(key), key.getBytes()))); - assertEquals(i + 1, map.size()); + assertEquals(i + 1, map.totalSize()); } - assert map.size() == 10; + assert map.totalSize() == 10; } /** @@ -188,7 +188,7 @@ public void testRehash() throws Exception { assertEquals(val, new String(valBytes)); } - assert map.size() == 10; + assert map.totalSize() == 10; } /** @@ -205,10 +205,10 @@ public void testGet() throws Exception { assertTrue(map.contains(hash(key), key.getBytes())); assertEquals(val, new String(map.get(hash(key), key.getBytes()))); - assertEquals(i + 1, map.size()); + assertEquals(i + 1, map.totalSize()); } - assert map.size() == 10; + assert map.totalSize() == 10; } /** @@ -225,10 +225,10 @@ public void testPut1() throws Exception { assertTrue(map.contains(hash(key), key.getBytes())); assertEquals(val, new String(map.get(hash(key), key.getBytes()))); - assertEquals(i + 1, map.size()); + assertEquals(i + 1, map.totalSize()); } - assertEquals(10, map.size()); + assertEquals(10, map.totalSize()); } /** @@ -247,16 +247,16 @@ public void testPut2() throws Exception { assertTrue(map.contains(hash(key), key.getBytes())); assertEquals(val1, new String(map.get(hash(key), key.getBytes()))); - assertEquals(i + 1, map.size()); + assertEquals(i + 1, map.totalSize()); assertFalse(map.put(hash(key), key.getBytes(), val2.getBytes())); assertTrue(map.contains(hash(key), key.getBytes())); assertEquals(val2, new String(map.get(hash(key), key.getBytes()))); - assertEquals(i + 1, map.size()); + assertEquals(i + 1, map.totalSize()); } - assertEquals(10, map.size()); + assertEquals(10, map.totalSize()); } /** @@ -274,7 +274,7 @@ public void testRemove() throws Exception { assertTrue(map.contains(hash(key), key.getBytes())); assertNotNull(map.get(hash(key), key.getBytes())); assertEquals(new String(map.get(hash(key), key.getBytes())), val); - assertEquals(1, map.size()); + assertEquals(1, map.totalSize()); byte[] val2 = map.remove(hash(key), key.getBytes()); @@ -282,10 +282,10 @@ public void testRemove() throws Exception { assertEquals(val, new String(val2)); assertFalse(map.contains(hash(key), key.getBytes())); assertNull(map.get(hash(key), key.getBytes())); - assertEquals(0, map.size()); + assertEquals(0, map.totalSize()); } - assertEquals(0, map.size()); + assertEquals(0, map.totalSize()); } /** @@ -303,17 +303,17 @@ public void testRemovex() throws Exception { assertTrue(map.contains(hash(key), key.getBytes())); assertNotNull(map.get(hash(key), key.getBytes())); assertEquals(new String(map.get(hash(key), key.getBytes())), val); - assertEquals(1, map.size()); + assertEquals(1, map.totalSize()); boolean rmvd = map.removex(hash(key), key.getBytes()); assertTrue(rmvd); assertFalse(map.contains(hash(key), key.getBytes())); assertNull(map.get(hash(key), key.getBytes())); - assertEquals(0, map.size()); + assertEquals(0, map.totalSize()); } - assertEquals(0, map.size()); + assertEquals(0, map.totalSize()); } /** @@ -377,12 +377,12 @@ public void testIterator() throws Exception { } } - assertEquals(map.size(), cnt); + assertEquals(map.totalSize(), cnt); } - assertEquals(max, map.size()); + assertEquals(max, map.totalSize()); - info("Stats [size=" + map.size() + ", rehashes=" + rehashes + ", releases=" + releases + ']'); + info("Stats [size=" + map.totalSize() + ", rehashes=" + rehashes + ", releases=" + releases + ']'); assertTrue(rehashes.get() > 0); assertEquals(rehashes.get(), releases.get()); @@ -454,9 +454,9 @@ public void testIteratorMultithreaded() throws Exception { } }, threads); - assertEquals(max * threads, map.size()); + assertEquals(max * threads, map.totalSize()); - info("Stats [size=" + map.size() + ", rehashes=" + rehashes + ", releases=" + releases + ']'); + info("Stats [size=" + map.totalSize() + ", rehashes=" + rehashes + ", releases=" + releases + ']'); assertTrue(rehashes.get() > 0); assertEquals(rehashes.get(), releases.get()); @@ -491,7 +491,7 @@ public void testInsertLoad() { assertTrue(map.contains(hash(key), key.getBytes())); assertNotNull(map.get(hash(key), key.getBytes())); assertEquals(new String(map.get(hash(key), key.getBytes())), val); - assertEquals(++cnt, map.size()); + assertEquals(++cnt, map.totalSize()); } } @@ -527,7 +527,7 @@ public void testPutLoad() { assertTrue(map.contains(hash(key), key.getBytes())); assertNotNull(map.get(hash(key), key.getBytes())); assertEquals(new String(map.get(hash(key), key.getBytes())), val); - assertEquals(++cnt, map.size()); + assertEquals(++cnt, map.totalSize()); } } @@ -563,7 +563,7 @@ public void testLru1() { info("Evicted: " + evictCnt); assertEquals(1, evictCnt.get()); - assertEquals(0, map.size()); + assertEquals(0, map.totalSize()); assertTrue(evictCnt.compareAndSet(1, 0)); } @@ -643,7 +643,7 @@ public void testLruMultithreaded() throws Exception { } }, 10); - info("Map stats [evicted=" + evictCnt + ", size=" + map.size() + ", allocated=" + map.allocatedSize() + + info("Map stats [evicted=" + evictCnt + ", size=" + map.totalSize() + ", allocated=" + map.allocatedSize() + ", freeSize=" + map.freeSize() + ']'); assertTrue(map.freeSize() >= 0); @@ -805,7 +805,7 @@ public Void call() throws IgniteCheckedException { for (byte[] key : keys) map.remove(key[0], key); - assertEquals(0, map.size()); + assertEquals(0, map.totalSize()); assertEquals(0, ((GridUnsafeMap)map).lruSize()); assertEquals(zeroAllocated, map.allocatedSize()); diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridIoManagerBenchmark0.java b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridIoManagerBenchmark0.java index 78b1aca24a649..94b8a879f3c05 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridIoManagerBenchmark0.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridIoManagerBenchmark0.java @@ -22,10 +22,10 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.managers.communication.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.communication.*; import org.apache.ignite.spi.communication.tcp.*; import org.apache.ignite.spi.discovery.tcp.*; @@ -123,7 +123,7 @@ public void testThroughput() throws Exception { new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg) { try { - rcv.send(sndNode, topic, (GridTcpCommunicationMessageAdapter)msg, PUBLIC_POOL); + rcv.send(sndNode, topic, (MessageAdapter)msg, PUBLIC_POOL); } catch (IgniteCheckedException e) { error("Failed to send message.", e); @@ -217,7 +217,7 @@ public void testLatency() throws Exception { new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg) { try { - rcv.send(sndNode, topic, (GridTcpCommunicationMessageAdapter)msg, PUBLIC_POOL); + rcv.send(sndNode, topic, (MessageAdapter)msg, PUBLIC_POOL); } catch (IgniteCheckedException e) { error("Failed to send message.", e); @@ -317,7 +317,7 @@ public void testVariableLoad() throws Exception { new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg) { try { - rcv.send(sndNode, topic, (GridTcpCommunicationMessageAdapter)msg, PUBLIC_POOL); + rcv.send(sndNode, topic, (MessageAdapter)msg, PUBLIC_POOL); } catch (IgniteCheckedException e) { error("Failed to send message.", e); diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java index 03926434fdbe0..1c63e60b2db8b 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java @@ -17,9 +17,9 @@ package org.apache.ignite.loadtests.communication; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; @@ -27,7 +27,7 @@ /** * */ -class GridTestMessage extends GridTcpCommunicationMessageAdapter implements Externalizable { +class GridTestMessage extends MessageAdapter implements Externalizable { /** */ private IgniteUuid id; @@ -109,12 +109,12 @@ public void bytes(byte[] bytes) { /** {@inheritDoc} */ @SuppressWarnings("CloneDoesntCallSuperClone") - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { throw new UnsupportedOperationException(); } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { // No-op. } diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java index 966dd6bd8289a..b99a901186b34 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java @@ -68,6 +68,7 @@ public GridCacheTestContext(GridTestKernalContext ctx) throws Exception { new CacheDataStructuresManager(), new GridCacheTtlManager(), new GridOsCacheDrManager(), + new IgniteCacheOsSerializationManager(), new CacheNoopJtaManager()); } } diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridAbstractCommunicationSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridAbstractCommunicationSelfTest.java index 1eb9f47adbc8b..2b7dac33824e8 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridAbstractCommunicationSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridAbstractCommunicationSelfTest.java @@ -19,10 +19,11 @@ import org.apache.ignite.*; import org.apache.ignite.cluster.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.junits.*; import org.apache.ignite.testframework.junits.spi.*; @@ -49,7 +50,7 @@ public abstract class GridAbstractCommunicationSelfTest> msgDestMap = new HashMap<>(); /** */ - protected static final Map> spis = new HashMap<>(); + protected static final Map> spis = new HashMap<>(); /** */ protected static final Collection nodes = new ArrayList<>(); @@ -61,16 +62,16 @@ public abstract class GridAbstractCommunicationSelfTest() { + @Override public MessageAdapter apply() { return new GridTestMessage(); } - }, GridTestMessage.DIRECT_TYPE); + }); } /** */ @SuppressWarnings({"deprecation"}) - private class MessageListener implements CommunicationListener { + private class MessageListener implements CommunicationListener { /** */ private final UUID locNodeId; @@ -84,7 +85,7 @@ private class MessageListener implements CommunicationListener spi : spis.values()) { + for (CommunicationSpi spi : spis.values()) { spi.onContextDestroyed(); spi.setListener(null); 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 b44f9ed5908de..9089e7c454acc 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 @@ -17,8 +17,8 @@ package org.apache.ignite.spi.communication; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.plugin.extensions.communication.*; import java.nio.*; import java.util.*; @@ -26,7 +26,7 @@ /** * Test message for communication SPI tests. */ -public class GridTestMessage extends GridTcpCommunicationMessageAdapter { +public class GridTestMessage extends MessageAdapter { /** */ public static final byte DIRECT_TYPE = (byte)200; @@ -95,7 +95,7 @@ public byte[] payload() { /** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) - @Override public GridTcpCommunicationMessageAdapter clone() { + @Override public MessageAdapter clone() { GridTestMessage msg = new GridTestMessage(); clone0(msg); @@ -104,7 +104,7 @@ public byte[] payload() { } /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + @Override protected void clone0(MessageAdapter _msg) { GridTestMessage _clone = (GridTestMessage)_msg; _clone.srcNodeId = srcNodeId; @@ -116,39 +116,39 @@ public byte[] payload() { /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + writer.setBuffer(buf); - if (!commState.typeWritten) { - if (!commState.putByte(directType())) + if (!typeWritten) { + if (!writer.writeByte(null, directType())) return false; - commState.typeWritten = true; + typeWritten = true; } - switch (commState.idx) { + switch (state) { case 0: - if (!commState.putUuid(srcNodeId)) + if (!writer.writeUuid(null, srcNodeId)) return false; - commState.idx++; + state++; case 1: - if (!commState.putLong(msgId)) + if (!writer.writeLong(null, msgId)) return false; - commState.idx++; + state++; case 2: - if (!commState.putLong(resId)) + if (!writer.writeLong(null, resId)) return false; - commState.idx++; + state++; case 3: - if (!commState.putByteArray(payload)) + if (!writer.writeByteArray(null, payload)) return false; - commState.idx++; + state++; } return true; @@ -157,40 +157,40 @@ public byte[] payload() { /** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); + reader.setBuffer(buf); - switch (commState.idx) { + switch (state) { case 0: - srcNodeId = commState.getUuid(); + srcNodeId = reader.readUuid(null); - if (srcNodeId == UUID_NOT_READ) + if (!reader.isLastRead()) return false; - commState.idx++; + state++; case 1: - if (buf.remaining() < 8) - return false; + msgId = reader.readLong(null); - msgId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 2: - if (buf.remaining() < 8) - return false; + resId = reader.readLong(null); - resId = commState.getLong(); + if (!reader.isLastRead()) + return false; - commState.idx++; + state++; case 3: - payload = commState.getByteArray(); + payload = reader.readByteArray(null); - if (payload == BYTE_ARR_NOT_READ) + if (!reader.isLastRead()) return false; - commState.idx++; + state++; } return true; diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridCacheDhtLockBackupSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridCacheDhtLockBackupSelfTest.java index f0ee2fe6ccb41..27c98c9a56125 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridCacheDhtLockBackupSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridCacheDhtLockBackupSelfTest.java @@ -22,11 +22,11 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.cache.distributed.near.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.*; import org.apache.ignite.marshaller.jdk.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.communication.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; @@ -259,7 +259,7 @@ private TestCommunicationSpi(Class delayedMsgCls, int delayTime) { * @param obj Message being sent. * @param srcNodeId Sender node id. */ - private void checkAwaitMessageType(GridTcpCommunicationMessageAdapter obj, UUID srcNodeId) { + private void checkAwaitMessageType(MessageAdapter obj, UUID srcNodeId) { try { GridIoMessage plainMsg = (GridIoMessage)obj; @@ -277,7 +277,7 @@ private void checkAwaitMessageType(GridTcpCommunicationMessageAdapter obj, UUID } /** {@inheritDoc} */ - @Override protected void notifyListener(UUID sndId, GridTcpCommunicationMessageAdapter msg, + @Override protected void notifyListener(UUID sndId, MessageAdapter msg, IgniteRunnable msgC) { checkAwaitMessageType(msg, sndId); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConcurrentConnectSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConcurrentConnectSelfTest.java index 4892db0b8fea2..175a4c5d2910e 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConcurrentConnectSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConcurrentConnectSelfTest.java @@ -20,11 +20,13 @@ import org.apache.ignite.*; import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.nio.*; +import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.communication.*; import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.junits.*; @@ -52,7 +54,7 @@ public class GridTcpCommunicationSpiConcurrentConnectSelfTest spiRsrcs = new ArrayList<>(); /** */ - protected static final List> spis = new ArrayList<>(); + protected static final List> spis = new ArrayList<>(); /** */ protected static final List nodes = new ArrayList<>(); @@ -64,12 +66,11 @@ public class GridTcpCommunicationSpiConcurrentConnectSelfTest() { + @Override public MessageAdapter apply() { return new GridTestMessage(); } - }, GridTestMessage.DIRECT_TYPE); + }); } /** @@ -82,7 +83,7 @@ public GridTcpCommunicationSpiConcurrentConnectSelfTest() { /** * */ - private static class MessageListener implements CommunicationListener { + private static class MessageListener implements CommunicationListener { /** */ private final CountDownLatch latch; @@ -100,7 +101,7 @@ private static class MessageListener implements CommunicationListener spi : spis) { + for (CommunicationSpi spi : spis) { spi.onContextDestroyed(); spi.setListener(null); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiLanTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiLanTest.java index 0e974b0598f5c..1c682644bcd78 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiLanTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiLanTest.java @@ -20,9 +20,9 @@ import mx4j.tools.adaptor.http.*; import org.apache.ignite.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.communication.*; import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.config.*; @@ -79,7 +79,7 @@ public GridTcpCommunicationSpiLanTest() { * Accumulating listener. */ @SuppressWarnings({"deprecation"}) - private class MessageListener implements CommunicationListener { + private class MessageListener implements CommunicationListener { /** Node id of local node. */ private final UUID locNodeId; @@ -100,7 +100,7 @@ private class MessageListener implements CommunicationListener spiRsrcs = new ArrayList<>(); /** SPIs */ - private static final Map> spis = + private static final Map> spis = new ConcurrentHashMap<>(); /** Listeners. */ @@ -73,11 +74,11 @@ public abstract class GridTcpCommunicationSpiMultithreadedSelfTest extends GridS private static boolean reject; static { - GridTcpCommunicationMessageFactory.registerCustom(new GridTcpCommunicationMessageProducer() { - @Override public GridTcpCommunicationMessageAdapter create(byte type) { + GridIoMessageFactory.registerCustom(GridTestMessage.DIRECT_TYPE, new CO() { + @Override public MessageAdapter apply() { return new GridTestMessage(); } - }, GridTestMessage.DIRECT_TYPE); + }); } /** @@ -93,7 +94,7 @@ protected GridTcpCommunicationSpiMultithreadedSelfTest(boolean useShmem) { * Accumulating listener. */ @SuppressWarnings({"deprecation"}) - private static class MessageListener implements CommunicationListener { + private static class MessageListener implements CommunicationListener { /** Node id of local node. */ private final UUID locNodeId; @@ -113,7 +114,7 @@ private static class MessageListener implements CommunicationListener spi : spis.values()) { + for (CommunicationSpi spi : spis.values()) { GridNioServer srv = U.field(spi, "nioSrvr"); Collection sessions = GridTestUtils.getFieldValue(srv, "sessions"); @@ -376,7 +377,7 @@ public void testPassThroughPerformance() throws Exception { ClusterNode to = nodes.get(1); - CommunicationSpi spi = spis.get(from.id()); + CommunicationSpi spi = spis.get(from.id()); while (cntr.getAndIncrement() < msgCnt) { GridTestMessage msg = new GridTestMessage(from.id(), msgId.getAndIncrement(), 0); @@ -414,7 +415,7 @@ private ClusterNode randomNode(Random rnd) { /** * @return Spi. */ - private CommunicationSpi newCommunicationSpi() { + private CommunicationSpi newCommunicationSpi() { TcpCommunicationSpi spi = new TcpCommunicationSpi(); if (!useShmem) @@ -445,7 +446,7 @@ private int getSpiCount() { Map ctxs = new HashMap<>(); for (int i = 0; i < getSpiCount(); i++) { - CommunicationSpi spi = newCommunicationSpi(); + CommunicationSpi spi = newCommunicationSpi(); GridTestUtils.setFieldValue(spi, "gridName", "grid-" + i); @@ -520,7 +521,7 @@ private int getSpiCount() { /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { - for (CommunicationSpi spi : spis.values()) { + for (CommunicationSpi spi : spis.values()) { spi.onContextDestroyed(); spi.setListener(null); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiRecoveryAckSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiRecoveryAckSelfTest.java index 641805d91e17c..2ba9086659740 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiRecoveryAckSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiRecoveryAckSelfTest.java @@ -19,11 +19,13 @@ import org.apache.ignite.*; import org.apache.ignite.cluster.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.nio.*; +import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.communication.*; import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.junits.*; @@ -55,12 +57,11 @@ public class GridTcpCommunicationSpiRecoveryAckSelfTest() { + @Override public MessageAdapter apply() { return new GridTestMessage(); } - }, GridTestMessage.DIRECT_TYPE); + }); } /** @@ -72,7 +73,7 @@ public GridTcpCommunicationSpiRecoveryAckSelfTest() { /** */ @SuppressWarnings({"deprecation"}) - private class TestListener implements CommunicationListener { + private class TestListener implements CommunicationListener { /** */ private ConcurrentHashSet msgIds = new ConcurrentHashSet<>(); @@ -80,7 +81,7 @@ private class TestListener implements CommunicationListener spi : spis) { + for (CommunicationSpi spi : spis) { spi.onContextDestroyed(); spi.setListener(null); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiRecoverySelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiRecoverySelfTest.java index cdd6ef6f92957..86b4e440ee702 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiRecoverySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiRecoverySelfTest.java @@ -20,11 +20,13 @@ import org.apache.ignite.*; import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.nio.*; +import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.*; import org.apache.ignite.testframework.*; @@ -64,11 +66,11 @@ public class GridTcpCommunicationSpiRecoverySelfTest * */ static { - GridTcpCommunicationMessageFactory.registerCustom(new GridTcpCommunicationMessageProducer() { - @Override public GridTcpCommunicationMessageAdapter create(byte type) { + GridIoMessageFactory.registerCustom(GridTestMessage.DIRECT_TYPE, new CO() { + @Override public MessageAdapter apply() { return new GridTestMessage(); } - }, GridTestMessage.DIRECT_TYPE); + }); } /** @@ -80,7 +82,7 @@ public GridTcpCommunicationSpiRecoverySelfTest() { /** */ @SuppressWarnings({"deprecation"}) - private class TestListener implements CommunicationListener { + private class TestListener implements CommunicationListener { /** */ private boolean block; @@ -94,7 +96,7 @@ private class TestListener implements CommunicationListener spi : spis) { + for (CommunicationSpi spi : spis) { spi.onContextDestroyed(); spi.setListener(null); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java index 4edb607b85a03..ce125a43f3886 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java @@ -72,6 +72,13 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceS return space != null ? space.count() : 0; } + /** {@inheritDoc} */ + @Override public long count(@Nullable String spaceName, Set parts) throws IgniteSpiException { + Space space = space(spaceName); + + return space.count(parts); + } + /** {@inheritDoc} */ @Override public byte[] read(@Nullable String spaceName, SwapKey key, SwapContext ctx) throws IgniteSpiException { @@ -171,6 +178,11 @@ private Space ensureSpace(String spaceName) { return space; } + /** + * @param evtType Event type. + * @param spaceName Space name. + * @param key Key bytes. + */ private void fireEvent(int evtType, String spaceName, @Nullable byte[] key) { SwapSpaceSpiListener lsnr0 = lsnr; @@ -178,10 +190,14 @@ private void fireEvent(int evtType, String spaceName, @Nullable byte[] key) { lsnr0.onSwapEvent(evtType, spaceName, key); } + /** + * + */ private class Space { /** Data storage. */ private ConcurrentMap data = new ConcurrentHashMap8<>(); + /** */ private final String name; /** @@ -214,6 +230,21 @@ public long count() { return data.size(); } + /** + * @param parts Partitions. + * @return Number of entries for given partitions. + */ + public long count(Set parts) { + int cnt = 0; + + for (SwapKey key : data.keySet()) { + if (parts.contains(key.partition())) + cnt++; + } + + return cnt; + } + /** * @param key Key to read. * @return Read bytes. @@ -318,6 +349,9 @@ public Collection partitions() { return parts; } + /** + * @return Iterator. + */ public IgniteSpiCloseableIterator keyIterator() { final Iterator it = data.keySet().iterator(); @@ -342,6 +376,9 @@ public IgniteSpiCloseableIterator keyIterator() { }; } + /** + * @return Raw iterator. + */ public IgniteSpiCloseableIterator> rawIterator() { final Iterator> it = data.entrySet().iterator(); @@ -378,6 +415,10 @@ public IgniteSpiCloseableIterator> rawIterator() { }; } + /** + * @param part Partition. + * @return Raw iterator for partition. + */ public IgniteSpiCloseableIterator> rawIterator(final int part) { final Iterator> it = data.entrySet().iterator(); diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridSpiTestContext.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridSpiTestContext.java index d8a34357636e3..80b9b96f39a3b 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/GridSpiTestContext.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridSpiTestContext.java @@ -21,18 +21,18 @@ import org.apache.ignite.cluster.*; import org.apache.ignite.events.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.direct.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.managers.eventstorage.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.plugin.security.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.swapspace.*; import org.jetbrains.annotations.*; import java.io.*; -import java.nio.*; import java.util.*; import java.util.concurrent.*; @@ -61,6 +61,12 @@ public class GridSpiTestContext implements IgniteSpiContext { /** */ private final ConcurrentMap cache = new ConcurrentHashMap<>(); + /** */ + private MessageFormatter formatter; + + /** */ + private MessageFactory factory; + /** {@inheritDoc} */ @Override public Collection remoteNodes() { return rmtNodes; @@ -489,16 +495,6 @@ public void triggerEvent(Event evt) { return null; } - /** {@inheritDoc} */ - @Override public boolean writeDelta(UUID nodeId, Object msg, ByteBuffer buf) { - return false; - } - - /** {@inheritDoc} */ - @Override public boolean readDelta(UUID nodeId, Class msgCls, ByteBuffer buf) { - return false; - } - /** {@inheritDoc} */ @Override public Collection authenticatedSubjects() { return Collections.emptyList(); @@ -516,12 +512,28 @@ public void triggerEvent(Event evt) { } /** {@inheritDoc} */ - @Override public GridTcpMessageFactory messageFactory() { - return new GridTcpMessageFactory() { - @Override public GridTcpCommunicationMessageAdapter create(byte type) { - return GridTcpCommunicationMessageFactory.create(type); - } - }; + @Override public MessageFormatter messageFormatter() { + if (formatter == null) { + formatter = new MessageFormatter() { + @Override public MessageWriter writer() { + return new DirectMessageWriter(); + } + + @Override public MessageReader reader() { + return new DirectMessageReader(messageFactory()); + } + }; + } + + return formatter; + } + + /** {@inheritDoc} */ + @Override public MessageFactory messageFactory() { + if (factory == null) + factory = new GridIoMessageFactory(messageFormatter(), null); + + return factory; } /** diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java index 4c28bc577339e..19ea25014a230 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java @@ -167,11 +167,6 @@ public IgniteMock( return null; } - /** {@inheritDoc} */ - @Override public IgnitePortables portables() { - return null; - } - /** {@inheritDoc} */ @Override public GridCache cache(@Nullable String name) { return null; diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index 4cd6417c392f3..fdbab73f1df4d 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -364,12 +364,12 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgniteCacheTxNearEnabledNoWriteThroughTest.class); suite.addTestSuite(IgniteCacheTxLocalNoWriteThroughTest.class); - suite.addTestSuite(IgniteCacheAtomicPeekTest.class); - suite.addTestSuite(IgniteCacheAtomicReplicatedPeekTest.class); - suite.addTestSuite(IgniteCacheAtomicLocalPeekTest.class); - suite.addTestSuite(IgniteCacheTxPeekTest.class); - suite.addTestSuite(IgniteCacheTxLocalPeekTest.class); - suite.addTestSuite(IgniteCacheTxReplicatedPeekTest.class); + suite.addTestSuite(IgniteCacheAtomicPeekModesTest.class); + suite.addTestSuite(IgniteCacheAtomicReplicatedPeekModesTest.class); + suite.addTestSuite(IgniteCacheAtomicLocalPeekModesTest.class); + suite.addTestSuite(IgniteCacheTxPeekModesTest.class); + suite.addTestSuite(IgniteCacheTxLocalPeekModesTest.class); + suite.addTestSuite(IgniteCacheTxReplicatedPeekModesTest.class); // TODO: IGNITE-114. // suite.addTestSuite(IgniteCacheInvokeReadThroughTest.class); diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/GridHadoopDefaultMapReducePlannerSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/GridHadoopDefaultMapReducePlannerSelfTest.java index de38897c6ffec..c76f0c4f32b92 100644 --- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/GridHadoopDefaultMapReducePlannerSelfTest.java +++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/GridHadoopDefaultMapReducePlannerSelfTest.java @@ -1221,5 +1221,10 @@ private static class MockIgnite extends IgniteSpringBean implements IgniteEx { @Override public IgniteFuture future() { return null; } + + /** {@inheritDoc} */ + @Override public ClusterGroup forCacheNodes(@Nullable String cacheName, Set distributionModes) { + return null; + } } } diff --git a/modules/indexing/src/test/java/org/apache/ignite/spi/communication/tcp/GridOrderedMessageCancelSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/spi/communication/tcp/GridOrderedMessageCancelSelfTest.java index a2b7ddf93937c..e9bc33e6ccaf8 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/spi/communication/tcp/GridOrderedMessageCancelSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/spi/communication/tcp/GridOrderedMessageCancelSelfTest.java @@ -24,9 +24,9 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.processors.cache.query.*; -import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; @@ -165,7 +165,7 @@ private void testMessageSet(IgniteInternalFuture fut) throws Exception { */ private static class CommunicationSpi extends TcpCommunicationSpi { /** {@inheritDoc} */ - @Override protected void notifyListener(UUID sndId, GridTcpCommunicationMessageAdapter msg, + @Override protected void notifyListener(UUID sndId, MessageAdapter msg, IgniteRunnable msgC) { try { GridIoMessage ioMsg = (GridIoMessage)msg; diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java index 74c810a592e71..6a46da1266bcd 100644 --- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java +++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java @@ -241,13 +241,6 @@ public void setConfiguration(IgniteConfiguration cfg) { return g.security(); } - /** {@inheritDoc} */ - @Override public IgnitePortables portables() { - assert g != null; - - return g.portables(); - } - /** {@inheritDoc} */ @Override public String name() { assert g != null; diff --git a/modules/yardstick/config/benchmark-store.properties b/modules/yardstick/config/benchmark-store.properties index c8e8cd72c695f..8a7c2652e5f74 100644 --- a/modules/yardstick/config/benchmark-store.properties +++ b/modules/yardstick/config/benchmark-store.properties @@ -42,7 +42,7 @@ JVM_OPTS=${JVM_OPTS}" \ # List of default probes. # Add DStatProbe or VmStatProbe if your OS supports it (e.g. if running on Linux). -BENCHMARK_DEFAULT_PROBES=ThroughputLatencyProbe,PercentileProbe,DStatProbe +BENCHMARK_DEFAULT_PROBES=ThroughputLatencyProbe,PercentileProbe # Packages where the specified benchmark is searched by reflection mechanism. BENCHMARK_PACKAGES=org.yardstickframework,org.apache.ignite.yardstick @@ -64,13 +64,30 @@ DRIVER_HOSTS=localhost # Number of nodes, used to wait for the specified number of nodes to start. nodesNum=$((`echo ${SERVER_HOSTS} | tr ',' '\n' | wc -l` + `echo ${DRIVER_HOSTS} | tr ',' '\n' | wc -l`)) +# Each benchmark warm_up set to 60 seconds (1 minute). +warm_up=60 + +# Each benchmark run set to 300 seconds (5 mins). +run=300 + # Run configuration which contains all benchmarks. -# Note that each benchmark is set to run for 300 seconds (5 mins) with warm-up set to 60 seconds (1 minute). CONFIGS="\ --cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetBenchmark -sn IgniteNode -ds atomic-get,\ --cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetTxBenchmark -sn IgniteNode -ds tx-get,\ --cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutBenchmark -sn IgniteNode -ds atomic-put,\ --cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutTxBenchmark -sn IgniteNode -ds tx-put,\ --cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetBenchmark -sn IgniteNode -ds atomic-put-get,\ --cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetTxBenchmark -sn IgniteNode -ds tx-put-get\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetBenchmark -sn IgniteNode -ds atomic-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetBenchmark -sn IgniteNode -cs -ds atomic-store-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetBenchmark -sn IgniteNode -cs -wb -ds atomic-writeBehind-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetTxBenchmark -sn IgniteNode -ds tx-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetTxBenchmark -sn IgniteNode -cs -ds tx-store-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetTxBenchmark -sn IgniteNode -cs -wb -ds tx-writeBehind-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutBenchmark -sn IgniteNode -ds atomic-put,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutBenchmark -sn IgniteNode -cs -ds atomic-store-put,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutBenchmark -sn IgniteNode -cs -wb -ds atomic-writeBehind-put,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutTxBenchmark -sn IgniteNode -ds tx-put,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutTxBenchmark -sn IgniteNode -cs -ds tx-store-put,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutTxBenchmark -sn IgniteNode -cs -wb -ds tx-writeBehind-put,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetBenchmark -sn IgniteNode -ds atomic-put-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetBenchmark -sn IgniteNode -cs -ds atomic-store-put-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetBenchmark -sn IgniteNode -cs -wb -ds atomic-writeBehind-put-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetTxBenchmark -sn IgniteNode -ds tx-put-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetTxBenchmark -sn IgniteNode -cs -ds tx-store-put-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w ${warm_up} -d ${run} -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetTxBenchmark -sn IgniteNode -cs -wb -ds tx-writeBehind-put-get\ " diff --git a/modules/yardstick/config/ignite-store-config.xml b/modules/yardstick/config/ignite-store-config.xml index b1076217b2cdb..4cbee370e026b 100644 --- a/modules/yardstick/config/ignite-store-config.xml +++ b/modules/yardstick/config/ignite-store-config.xml @@ -24,6 +24,18 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> + + + + + + + + + + @@ -93,25 +105,9 @@ - - - - - - - - - - - + - - - - - - @@ -133,25 +129,9 @@ - - - - - - - - - - - + - - - - - - diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java index 12047209164e1..72d701374e0ba 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java @@ -86,6 +86,14 @@ public class IgniteBenchmarkArguments { @Parameter(names = {"-j", "--jobs"}, description = "Number of jobs for compute benchmarks") private int jobs = 10; + /** */ + @Parameter(names = {"-cs", "--cacheStore"}, description = "Enable or disable cache store readThrough, writeThrough") + private boolean storeEnabled; + + /** */ + @Parameter(names = {"-wb", "--writeBehind"}, description = "Enable or disable writeBehind for cache store") + private boolean writeBehind; + /** * @return Transaction concurrency. */ @@ -198,6 +206,20 @@ public int jobs() { return jobs; } + /** + * @return {@code True} if enabled readThrough, writeThrough for cache. + */ + public boolean isStoreEnabled() { + return storeEnabled; + } + + /** + * @return {@code True} if enabled writeBehind for cache store. + */ + public boolean isWriteBehind() { + return writeBehind; + } + /** * @return Description. */ diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java index 94e6f52850823..7d6439846c400 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java @@ -105,6 +105,11 @@ public IgniteNode(boolean clientMode, Ignite ignite) { cc.setEvictionPolicy(new CacheLruEvictionPolicy(50000)); } + cc.setReadThrough(args.isStoreEnabled()); + + cc.setWriteThrough(args.isStoreEnabled()); + + cc.setWriteBehindEnabled(args.isWriteBehind()); } TransactionConfiguration tc = c.getTransactionConfiguration(); diff --git a/pom.xml b/pom.xml index 176dc7bfb5554..498ce6391b88f 100644 --- a/pom.xml +++ b/pom.xml @@ -116,6 +116,7 @@ modules/slf4j modules/jcl modules/schema-load + modules/codegen @@ -283,6 +284,7 @@ **/*.* + work/** **/*.txt **/*.jks **/*.pem @@ -800,7 +802,7 @@ Ignite plugin API - org.apache.ignite.plugin:org.apache.ignite.plugin.extensions:org.apache.ignite.plugin.extensions.communication:org.apache.ignite.plugin.extensions.discovery:org.apache.ignite.visor.plugin + org.apache.ignite.plugin:org.apache.ignite.plugin.extensions:org.apache.ignite.plugin.extensions.communication:org.apache.ignite.visor.plugin Logging @@ -918,7 +920,7 @@ http://hadoop.apache.org/docs/current/api/ assembly/docfiles/javadoc.css - com.*:org.jetbrains.*:org.pcollections:*.jdk8:*.tests:*.tools:*.typedef:*.examples:*.client:*.kernal:*.internal:*.util:*.dr:*.compute.gridify.aop:*.spi.authentication:*.spi.securesession:*.spi.discovery.tcp.messages:*.spi.discovery.tcp.internal:*.spi.deployment.uri.scanners:*.spi.deployment.uri.tasks:*.spi.indexing.h2.opt:org.apache.ignite.portables:org.apache.ignite.yardstick:org.apache.ignite.schema.* + com.*:org.jetbrains.*:org.pcollections:*.jdk8:*.tests:*.tools:*.typedef:*.examples:*.client:*.kernal:*.internal:*.util:*.dr:*.compute.gridify.aop:*.spi.authentication:*.spi.securesession:*.spi.discovery.tcp.messages:*.spi.discovery.tcp.internal:*.spi.deployment.uri.scanners:*.spi.deployment.uri.tasks:*.spi.indexing.h2.opt:org.apache.ignite.portables:org.apache.ignite.yardstick:org.apache.ignite.schema.*:org.apache.ignite.codegen Common Grid APIs @@ -1010,7 +1012,7 @@ Ignite plugin API - org.apache.ignite.plugin:org.apache.ignite.plugin.extensions:org.apache.ignite.plugin.extensions.communication:org.apache.ignite.plugin.extensions.discovery:org.apache.ignite.visor.plugin + org.apache.ignite.plugin:org.apache.ignite.plugin.extensions:org.apache.ignite.plugin.extensions.communication:org.apache.ignite.visor.plugin Logging