diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/QueryTxEntry.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/QueryTxEntry.java index 36f2d9dceee84..da49c14612be7 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/QueryTxEntry.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/QueryTxEntry.java @@ -29,6 +29,7 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; /** * Class to pass to remote nodes transaction changes. @@ -38,7 +39,7 @@ * @see ExecutionContext#transactionChanges(int, int[], Function, Comparator) * @see QueryStartRequest#queryTransactionEntries() */ -public class QueryTxEntry implements CalciteContextMarshallableMessage { +public class QueryTxEntry implements CalciteContextMarshallableMessage, CacheIdAware { /** Cache id. */ @Order(0) int cacheId; @@ -75,8 +76,8 @@ public QueryTxEntry(int cacheId, KeyCacheObject key, CacheObject val, GridCacheV this.ver = ver; } - /** @return Cache id. */ - public int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } @@ -97,12 +98,6 @@ public GridCacheVersion version() { /** {@inheritDoc} */ @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - CacheObjectContext coctx = ctx.cacheContext(cacheId).cacheObjectContext(); - - key.prepareMarshal(coctx); - - if (val != null) - val.prepareMarshal(coctx); } /** {@inheritDoc} */ diff --git a/modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java b/modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java index 7874b5dcd8c42..72961bca47b79 100644 --- a/modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java +++ b/modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.BitSet; import java.util.Collection; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -46,12 +47,14 @@ import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeVariable; import javax.lang.model.util.Elements; import javax.tools.Diagnostic; import javax.tools.FileObject; import javax.tools.JavaFileObject; import javax.tools.StandardLocation; import org.apache.ignite.internal.systemview.SystemViewRowAttributeWalkerProcessor; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.SB; import org.jetbrains.annotations.Nullable; @@ -74,7 +77,7 @@ public class MessageSerializerGenerator { public static final String NL = System.lineSeparator(); /** */ - private static final String CLS_JAVADOC = "/** " + NL + + private static final String CLS_JAVADOC = "/**" + NL + " * This class is generated automatically." + NL + " *" + NL + " * @see org.apache.ignite.internal.MessageProcessor" + NL + @@ -99,6 +102,9 @@ public class MessageSerializerGenerator { /** Collection of lines for {@code readFrom} method. */ private final List read = new ArrayList<>(); + /** */ + private final List marshall = new ArrayList<>(); + /** Collection of message-specific imports. */ private final Set imports = new TreeSet<>(); @@ -189,9 +195,14 @@ private String generateSerializerCode(String serClsName) throws IOException { writer.write(TAB + "}" + NL); - writer.write("}"); + if (!marshall.isEmpty()) { + writer.write(NL); - writer.write(NL); + for (String p: marshall) + writer.write(p + NL); + } + + writer.write("}"); return writer.toString(); } @@ -204,23 +215,23 @@ private void writeConstructor(Writer writer, String serClsName) throws IOExcepti ++indent; - writer.write(identedLine(METHOD_JAVADOC)); + writer.write(indentedLine(METHOD_JAVADOC)); writer.write(NL); - writer.write(identedLine("public " + serClsName + "(Marshaller marshaller, ClassLoader clsLdr) {")); + writer.write(indentedLine("public " + serClsName + "(Marshaller marshaller, ClassLoader clsLdr) {")); writer.write(NL); ++indent; - writer.write(identedLine("this.marshaller = marshaller;")); + writer.write(indentedLine("this.marshaller = marshaller;")); writer.write(NL); - writer.write(identedLine("this.clsLdr = clsLdr;")); + writer.write(indentedLine("this.clsLdr = clsLdr;")); --indent; writer.write(NL); - writer.write(identedLine("}")); + writer.write(indentedLine("}")); writer.write(NL); --indent; @@ -242,6 +253,264 @@ private void generateMethods(List fields) throws Exception { finish(write, false, false); finish(read, true, marshallableMessage()); + + generateMarshallMethods(fields); + } + + /** */ + private void generateMarshallMethods(List orderedFields) throws Exception { + imports.add("org.apache.ignite.IgniteCheckedException"); + imports.add("org.apache.ignite.internal.processors.cache.CacheObjectValueContext"); + imports.add("org.apache.ignite.internal.processors.cache.GridCacheSharedContext"); + imports.add("org.apache.ignite.internal.processors.cache.GridCacheContext"); + + indent = 1; + + marshall.add(indentedLine(METHOD_JAVADOC)); + + marshall.add(indentedLine( + "@Override public void prepareMarshal(" + simpleNameWithGeneric(type) + + " msg, GridCacheSharedContext sctx, GridCacheContext nested) throws IgniteCheckedException {")); + + indent++; + + if (isCacheIdAwareMessage(type)) + marshall.add( + indentedLine("GridCacheContext ctx = nested == null ? sctx.cacheContext(msg.cacheId()) : nested;")); + else + marshall.add(indentedLine("GridCacheContext ctx = nested;")); + + for (VariableElement field : orderedFields) { + List marshalled = marshall(field.asType(), fieldAccessor(field)); + + if (!marshalled.isEmpty()) { + if (!marshall.get(marshall.size() - 1).equals(EMPTY)) + marshall.add(EMPTY); + + marshall.addAll(marshalled); + } + } + + if (marshallableMessage()) { + marshall.add(EMPTY); + + marshall.add(indentedLine("msg.prepareMarshal(marshaller);")); + } + + indent--; + + marshall.add(indentedLine("}")); + } + + /** */ + private List marshall(TypeMirror t, String accessor) { + if (t.getKind() == TypeKind.ARRAY) { + TypeMirror comp = ((ArrayType)t).getComponentType(); + + if (comp.getKind() == TypeKind.DECLARED) { + List code = new ArrayList<>(); + + imports.add(((QualifiedNameable)((DeclaredType)comp).asElement()).getQualifiedName().toString()); + + code.add(indentedLine("if (%s != null) {", accessor)); + + indent++; + + String el = "e" + indent; + + code.add(indentedLine("for (%s %s : %s) {", ((DeclaredType)comp).asElement().getSimpleName().toString(), el, accessor)); + + indent++; + + List res = marshall(comp, el); + + code.addAll(res); + + indent--; + + code.add(indentedLine("}")); + + indent--; + + code.add(indentedLine("}")); + + if (res.isEmpty()) + return Collections.emptyList(); + else + return code; + } + } + else if (t.getKind() == TypeKind.DECLARED || t.getKind() == TypeKind.TYPEVAR) { + if (isMessage(t)) { + List code = new ArrayList<>(); + + code.add(indentedLine("if (%s != null)", accessor)); + + indent++; + + code.add(indentedLine( + "sctx.gridIO().messageFactory().serializer(%s.directType()).prepareMarshal(%s, sctx, ctx);", + accessor, + accessor)); + + indent--; + + return code; + } + else if (isCacheObject(t)) { + List code = new ArrayList<>(); + + code.add(indentedLine("if (%s != null)", accessor)); + + indent++; + + code.add(indentedLine("%s.prepareMarshal(ctx != null ? ctx.cacheObjectContext() : null);", accessor)); + + indent--; + + return code; + } + else if (assignableFrom(erasedType(t), type(Map.class.getName()))) { + List args = ((DeclaredType)t).getTypeArguments(); + + TypeMirror keyType = args.get(0); + TypeMirror valType = args.get(1); + + List code = new ArrayList<>(); + + code.add(indentedLine("if (%s != null) {", accessor)); + + indent++; + + String el = "e" + indent; + + indent++; // Emulating subsequent indent. + List keyRes = marshall(keyType, el); + List valRes = marshall(valType, el); + indent--; + + if (!keyRes.isEmpty() && (keyType.getKind() == TypeKind.DECLARED || keyType.getKind() == TypeKind.TYPEVAR)) { + Element elem = element(keyType); + + imports.add(((QualifiedNameable)(elem)).getQualifiedName().toString()); + imports.add("java.util.Collection"); + + String type = elem.getSimpleName().toString(); + + code.add(indentedLine("for (%s %s : ((Collection)%s.keySet())) {", type, el, type, accessor)); + + indent++; + + code.addAll(keyRes); + + indent--; + + code.add(indentedLine("}")); + } + + if (!valRes.isEmpty() && (valType.getKind() == TypeKind.DECLARED || valType.getKind() == TypeKind.TYPEVAR)) { + Element elem = element(valType); + + imports.add(((QualifiedNameable)(elem)).getQualifiedName().toString()); + imports.add("java.util.Collection"); + + String type = elem.getSimpleName().toString(); + + code.add(indentedLine("for (%s %s : ((Collection)%s.values())) {", type, el, type, accessor)); + + indent++; + + code.addAll(valRes); + + indent--; + + code.add(indentedLine("}")); + } + + indent--; + + code.add(indentedLine("}")); + + if (keyRes.isEmpty() && valRes.isEmpty()) + return Collections.emptyList(); + else + return code; + } + else if (assignableFrom(erasedType(t), type(Collection.class.getName()))) { + List args = ((DeclaredType)t).getTypeArguments(); + + TypeMirror arg = args.get(0); + + if ((arg.getKind() == TypeKind.DECLARED || arg.getKind() == TypeKind.TYPEVAR)) { + List code = new ArrayList<>(); + + Element elem = element(arg); + + imports.add(((QualifiedNameable)(elem)).getQualifiedName().toString()); + imports.add("java.util.Collection"); + + String el = "e" + indent; + + code.add(indentedLine("if (%s != null) {", accessor)); + + indent++; + + String type = elem.getSimpleName().toString(); + + code.add(indentedLine("for (%s %s : (Collection)%s) {", type, el, type, accessor)); + + indent++; + + List res = marshall(arg, el); + + code.addAll(res); + + indent--; + + code.add(indentedLine("}")); + + indent--; + + code.add(indentedLine("}")); + + if (res.isEmpty()) + return Collections.emptyList(); + else + return code; + } + } + } + + return Collections.emptyList(); + } + + /** */ + private boolean isCacheObject(TypeMirror type) { + return assignableFrom(type, type("org.apache.ignite.internal.processors.cache.CacheObject")); + } + + /** */ + private boolean isMessage(TypeMirror type) { + return assignableFrom(type, type(MESSAGE_INTERFACE)); + } + + /** True if {@code te} extends {@code CacheIdAware} and therefore carries its own per-cache {@code cacheId()}. */ + private boolean isCacheIdAwareMessage(TypeElement te) { + return assignableFrom(te.asType(), type("org.apache.ignite.plugin.extensions.communication.CacheIdAware")); + } + + /** */ + private String fieldAccessor(VariableElement field) { + String name = field.getSimpleName().toString(); + + return "msg." + name; + } + + /** */ + private Element element(TypeMirror type) { + return type.getKind() == TypeKind.DECLARED ? + ((DeclaredType)type).asElement() : + ((DeclaredType)((TypeVariable)type).getUpperBound()).asElement(); } /** @@ -262,57 +531,31 @@ private void generateMethods(List fields) throws Exception { private void start(Collection code, boolean write) { indent = 1; - code.add(identedLine(METHOD_JAVADOC)); + code.add(indentedLine(METHOD_JAVADOC)); - code.add(identedLine("@Override public boolean %s(" + type.getSimpleName() + " msg, %s) {", + code.add(indentedLine("@Override public boolean %s(" + simpleNameWithGeneric(type) + " msg, %s) {", write ? "writeTo" : "readFrom", write ? "MessageWriter writer" : "MessageReader reader")); indent++; if (write) { - code.add(identedLine("if (!writer.isHeaderWritten()) {")); + code.add(indentedLine("if (!writer.isHeaderWritten()) {")); indent++; returnFalseIfWriteFailed(code, "writer.writeHeader", "directType()"); - if (write && marshallableMessage()) { - imports.add("org.apache.ignite.IgniteCheckedException"); - imports.add("org.apache.ignite.IgniteException"); - - code.add(EMPTY); - - code.add(identedLine("try {")); - - indent++; - - code.add(identedLine("msg.prepareMarshal(marshaller);")); - - indent--; - - code.add(identedLine("}")); - code.add(identedLine("catch (IgniteCheckedException e) {")); - - indent++; - - code.add(identedLine("throw new IgniteException(\"Failed to marshal object \" + msg.getClass().getSimpleName(), e);")); - - indent--; - - code.add(identedLine("}")); - } - code.add(EMPTY); - code.add(identedLine("writer.onHeaderWritten();")); + code.add(indentedLine("writer.onHeaderWritten();")); indent--; - code.add(identedLine("}")); + code.add(indentedLine("}")); code.add(EMPTY); } - code.add(identedLine("switch (%s.state()) {", write ? "writer" : "reader")); + code.add(indentedLine("switch (%s.state()) {", write ? "writer" : "reader")); } /** @@ -341,14 +584,14 @@ private void processField(VariableElement field, int opt) throws Exception { * @param opt Case option. */ private void writeField(VariableElement field, int opt) throws Exception { - write.add(identedLine("case %d:", opt)); + write.add(indentedLine("case %d:", opt)); indent++; returnFalseIfWriteFailed(field); write.add(EMPTY); - write.add(identedLine("writer.incrementState();")); + write.add(indentedLine("writer.incrementState();")); write.add(EMPTY); indent--; @@ -369,14 +612,14 @@ private void writeField(VariableElement field, int opt) throws Exception { * @param opt Case option. */ private void readField(VariableElement field, int opt) throws Exception { - read.add(identedLine("case %d:", opt)); + read.add(indentedLine("case %d:", opt)); indent++; returnFalseIfReadFailed(field); read.add(EMPTY); - read.add(identedLine("reader.incrementState();")); + read.add(indentedLine("reader.incrementState();")); read.add(EMPTY); indent--; @@ -538,11 +781,11 @@ private String typeNameToFieldName(String typeName) { private void returnFalseIfWriteFailed(Collection code, String accessor, @Nullable String... args) { String argsStr = String.join(", ", args); - code.add(identedLine("if (!%s(msg.%s))", accessor, argsStr)); + code.add(indentedLine("if (!%s(msg.%s))", accessor, argsStr)); indent++; - code.add(identedLine(RETURN_FALSE_STMT)); + code.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -554,15 +797,15 @@ private void returnFalseIfWriteFailed(Collection code, VariableElement f String argsStr = String.join(", ", args); if (type.equals(field.getEnclosingElement())) - code.add(identedLine("if (!%s(msg.%s))", accessor, argsStr)); + code.add(indentedLine("if (!%s(msg.%s))", accessor, argsStr)); else { // Field has to be requested from a super class object. - code.add(identedLine("if (!%s(((%s)msg).%s))", accessor, field.getEnclosingElement().getSimpleName(), argsStr)); + code.add(indentedLine("if (!%s(((%s)msg).%s))", accessor, field.getEnclosingElement().getSimpleName(), argsStr)); } indent++; - code.add(identedLine(RETURN_FALSE_STMT)); + code.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -577,16 +820,16 @@ private void returnFalseIfEnumWriteFailed( String mapperCall, String fieldGetterCall) { if (type.equals(field.getEnclosingElement())) - code.add(identedLine("if (!%s(%s(msg.%s)))", writerCall, mapperCall, fieldGetterCall)); + code.add(indentedLine("if (!%s(%s(msg.%s)))", writerCall, mapperCall, fieldGetterCall)); else { // Field has to be requested from a super class object. - code.add(identedLine("if (!%s(%s(((%s)msg).%s)))", + code.add(indentedLine("if (!%s(%s(((%s)msg).%s)))", writerCall, mapperCall, field.getEnclosingElement().getSimpleName(), fieldGetterCall)); } indent++; - code.add(identedLine(RETURN_FALSE_STMT)); + code.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -880,20 +1123,20 @@ private void returnFalseIfReadFailed(VariableElement field, String mtd, String.. String argsStr = String.join(", ", args); if (type.equals(field.getEnclosingElement())) - read.add(identedLine("msg.%s = %s(%s);", field.getSimpleName().toString(), mtd, argsStr)); + read.add(indentedLine("msg.%s = %s(%s);", field.getSimpleName().toString(), mtd, argsStr)); else { // Field has to be requested from a super class object. - read.add(identedLine("((%s)msg).%s = %s(%s);", + read.add(indentedLine("((%s)msg).%s = %s(%s);", field.getEnclosingElement().getSimpleName(), field.getSimpleName().toString(), mtd, argsStr)); } read.add(EMPTY); - read.add(identedLine("if (!reader.isLastRead())")); + read.add(indentedLine("if (!reader.isLastRead())")); indent++; - read.add(identedLine(RETURN_FALSE_STMT)); + read.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -912,20 +1155,20 @@ private void returnFalseIfEnumReadFailed(VariableElement field, String mapperDec readOp = line("%s(%s, reader.readByte())", mapperDecodeCallStmnt, enumValuesFieldName); if (type.equals(field.getEnclosingElement())) - read.add(identedLine("msg.%s = %s;", field.getSimpleName().toString(), readOp)); + read.add(indentedLine("msg.%s = %s;", field.getSimpleName().toString(), readOp)); else { // Field has to be requested from a super class object. - read.add(identedLine("((%s)msg).%s = %s;", + read.add(indentedLine("((%s)msg).%s = %s;", field.getEnclosingElement().getSimpleName(), field.getSimpleName().toString(), readOp)); } read.add(EMPTY); - read.add(identedLine("if (!reader.isLastRead())")); + read.add(indentedLine("if (!reader.isLastRead())")); indent++; - read.add(identedLine(RETURN_FALSE_STMT)); + read.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -937,36 +1180,36 @@ private void finish(List code, boolean read, boolean marshallable) { if (EMPTY.equals(lastLine)) code.remove(code.size() - 1); - code.add(identedLine("}")); + code.add(indentedLine("}")); code.add(EMPTY); if (read && marshallable) { imports.add("org.apache.ignite.IgniteCheckedException"); imports.add("org.apache.ignite.IgniteException"); - code.add(identedLine("try {")); + code.add(indentedLine("try {")); indent++; - code.add(identedLine("msg.finishUnmarshal(marshaller, clsLdr);")); + code.add(indentedLine("msg.finishUnmarshal(marshaller, clsLdr);")); indent--; - code.add(identedLine("}")); - code.add(identedLine("catch (IgniteCheckedException e) {")); + code.add(indentedLine("}")); + code.add(indentedLine("catch (IgniteCheckedException e) {")); indent++; - code.add(identedLine("throw new IgniteException(\"Failed to unmarshal object \" + msg.getClass().getSimpleName(), e);")); + code.add(indentedLine("throw new IgniteException(\"Failed to unmarshal object \" + msg.getClass().getSimpleName(), e);")); indent--; - code.add(identedLine("}")); + code.add(indentedLine("}")); code.add(EMPTY); } - code.add(identedLine("return true;")); + code.add(indentedLine("return true;")); } /** @@ -974,7 +1217,7 @@ private void finish(List code, boolean read, boolean marshallable) { * * @return Line with current indent. */ - private String identedLine(String format, Object... args) { + private String indentedLine(String format, Object... args) { SB sb = new SB(); for (int i = 0; i < indent; i++) @@ -1006,9 +1249,9 @@ private void writeClassFields(Writer writer) throws IOException { indent = 1; for (String field: fields) { - writer.write(identedLine(METHOD_JAVADOC)); + writer.write(indentedLine(METHOD_JAVADOC)); writer.write(NL); - writer.write(identedLine(field)); + writer.write(indentedLine(field)); writer.write(NL); } writer.write(NL); @@ -1048,7 +1291,7 @@ private void writeClassHeader(Writer writer, String pkgName, String serClsName) writer.write(CLS_JAVADOC); writer.write(NL); - writer.write("public class " + serClsName + " implements MessageSerializer<" + type.getSimpleName() + "> {" + NL); + writer.write("public class " + serClsName + " implements MessageSerializer<" + simpleNameWithGeneric(type) + "> {" + NL); } /** */ @@ -1144,4 +1387,23 @@ private void checkTypeForCompress(TypeMirror type) { throw new IllegalArgumentException("Compress annotation is used for an unsupported type: " + type); } + + /** @return Simple class name. */ + private String simpleNameWithGeneric(TypeElement te) { + if (F.size(te.getTypeParameters()) == 0) + return te.getSimpleName().toString(); + + StringBuilder generic = new StringBuilder(te.getSimpleName() + "<"); + + for (int i = 0; i < F.size(te.getTypeParameters()); i++) { + if (i > 0) + generic.append(", "); + + generic.append("?"); + } + + generic.append(">"); + + return generic.toString(); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java index 1ac2ce2bc9227..354284e03ed0f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java @@ -563,7 +563,7 @@ void p2pUnmarshal(Marshaller marsh, @Nullable ClassLoader ldr) throws IgniteChec } /** {@inheritDoc} */ - @Override public void prepare(GridDeploymentInfo depInfo) { + @Override public void prepareDeployment(GridDeploymentInfo depInfo) { assert evt instanceof CacheEvent; this.depInfo = depInfo; 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 b94f0df3ca02c..32e94aa663279 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 @@ -1314,7 +1314,7 @@ else if (e instanceof IgniteCheckedException) } /** */ - private void initMessageFactory() throws IgniteCheckedException { + public void initMessageFactory() throws IgniteCheckedException { MessageFactoryProvider[] msgs = ctx.plugins().extensions(MessageFactoryProvider.class); List compMsgs = new ArrayList<>(); 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 9294efd015356..d5e08319e4657 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 @@ -128,6 +128,7 @@ import org.apache.ignite.plugin.extensions.communication.MessageFactory; import org.apache.ignite.plugin.extensions.communication.MessageFormatter; import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; import org.apache.ignite.plugin.extensions.communication.MessageWriter; import org.apache.ignite.spi.IgniteSpiException; import org.apache.ignite.spi.communication.CommunicationListener; @@ -1984,6 +1985,11 @@ private void send( GridIoMessage ioMsg = createGridIoMessage(topic, topicOrd, msg, plc, ordered, timeout, skipOnTimeout); + MessageSerializer ser = ctx.io().messageFactory().serializer(ioMsg.directType()); + + if (ser != null) + ser.prepareMarshal(ioMsg, ctx.cache().context(), null); + if (locNodeId.equals(node.id())) { assert plc != P2P_POOL; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicate.java index 36312a1591135..93e06fc27c73a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicate.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicate.java @@ -25,12 +25,6 @@ * */ public interface CacheEntryPredicate extends IgnitePredicate, Message { - /** - * @param ctx Context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException; - /** * @param ctx Context. * @param ldr Class loader. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java index 0c30dc615aa66..b1017e9708ae8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java @@ -124,11 +124,4 @@ public CacheEntryPredicateType type() { if (type == CacheEntryPredicateType.VALUE) val.finishUnmarshal(ctx.cacheObjectContext(), ldr); } - - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { - if (type == CacheEntryPredicateType.VALUE) - val.prepareMarshal(ctx.cacheObjectContext()); - } - } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java index 1276c6b63c82c..2f76570ff6ee5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java @@ -111,19 +111,6 @@ public CacheObject result() { return ErrorMessage.error(errMsg); } - /** - * @param ctx Cache context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { - key.prepareMarshal(ctx.cacheObjectContext()); - - assert unprepareRes == null : "marshalResult() was not called for the result: " + this; - - if (res != null) - res.prepareMarshal(ctx.cacheObjectContext()); - } - /** * Converts the entry processor unprepared result to a cache object instance. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeployable.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeployable.java index 057ce897bac52..9d8f289bbe1c1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeployable.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeployable.java @@ -28,7 +28,7 @@ public interface GridCacheDeployable { * * @param depInfo Deployment information. */ - public void prepare(GridDeploymentInfo depInfo); + public void prepareDeployment(GridDeploymentInfo depInfo); /** * @return Deployment bean. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java index ce2ceaa577771..29abdca600257 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java @@ -411,7 +411,7 @@ public void prepare(GridCacheDeployable deployable) throws IgnitePeerToPeerClass checkDeploymentIsCorrect(dep, deployable, true); if (dep != null) - deployable.prepare(dep); + deployable.prepareDeployment(dep); if (log.isDebugEnabled()) log.debug("Prepared grid cache deployable [dep=" + dep + ", deployable=" + deployable + ']'); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java index d8d710f62368f..9369e827aaccf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java @@ -18,17 +18,19 @@ package org.apache.ignite.internal.processors.cache; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; /** * Entry information that gets passed over wire. */ -public class GridCacheEntryInfo implements Message { +public class GridCacheEntryInfo implements MarshallableMessage, CacheIdAware { /** */ private static final int SIZE_OVERHEAD = 3 * 8 /* reference */ + 4 /* int */ + 2 * 8 /* long */ + 32 /* version */; @@ -63,10 +65,8 @@ public class GridCacheEntryInfo implements Message { /** Deleted flag. */ private boolean deleted; - /** - * @return Cache ID. - */ - public int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } @@ -201,26 +201,8 @@ public int marshalledSize(CacheObjectContext ctx) throws IgniteCheckedException return SIZE_OVERHEAD + size; } - /** - * @param ctx Cache context. - * @throws IgniteCheckedException In case of error. - */ - public void marshal(GridCacheContext ctx) throws IgniteCheckedException { - marshal(ctx.cacheObjectContext()); - } - - /** - * @param ctx Cache context. - * @throws IgniteCheckedException In case of error. - */ - public void marshal(CacheObjectContext ctx) throws IgniteCheckedException { - assert key != null; - - key.prepareMarshal(ctx); - - if (val != null) - val.prepareMarshal(ctx); - + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { if (expireTime == 0) expireTime = -1; else { @@ -231,6 +213,10 @@ public void marshal(CacheObjectContext ctx) throws IgniteCheckedException { } } + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + } + /** * Unmarshalls entry. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java index f0ebb72b7b5b1..1236d67451ac1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java @@ -20,20 +20,19 @@ import org.apache.ignite.internal.Order; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; /** * Message related to particular cache. */ -public abstract class GridCacheIdMessage extends GridCacheMessage { +public abstract class GridCacheIdMessage extends GridCacheMessage implements CacheIdAware { /** Cache ID. */ @GridToStringInclude @Order(0) public int cacheId; - /** - * @return Cache ID. - */ - public int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } 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 4dfdb6b35997d..ef68949ff6bfe 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 @@ -1095,7 +1095,7 @@ private boolean onSend(GridCacheMessage msg, @Nullable UUID destNodeId) throws I msg.messageId(idGen.incrementAndGet()); if (destNodeId == null || !cctx.localNodeId().equals(destNodeId)) { - msg.prepareMarshal(cctx); + msg.prepareDeployment(cctx); if (msg instanceof GridCacheDeployable && msg.addDeploymentInfo()) cctx.deploy().prepare((GridCacheDeployable)msg); 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 ec670da2d1cbf..a4a3a0a2aeba3 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 @@ -32,7 +32,6 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.T2; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.Marshaller; @@ -204,8 +203,8 @@ public void lastAffinityChangedTopologyVersion(AffinityTopologyVersion topVer) { * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void prepareObject(@Nullable Object o, GridCacheContext ctx) throws IgniteCheckedException { - prepareObject(o, ctx.shared()); + protected final void prepareObjectDeployment(@Nullable Object o, GridCacheContext ctx) throws IgniteCheckedException { + prepareObjectDeployment(o, ctx.shared()); } /** @@ -213,14 +212,14 @@ protected final void prepareObject(@Nullable Object o, GridCacheContext ctx) thr * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void prepareObject(@Nullable Object o, GridCacheSharedContext ctx) throws IgniteCheckedException { + protected final void prepareObjectDeployment(@Nullable Object o, GridCacheSharedContext ctx) throws IgniteCheckedException { assert addDepInfo || forceAddDepInfo; if (!skipPrepare && o != null) { GridDeploymentInfo d = ctx.deploy().globalDeploymentInfo(); if (d != null) { - prepare(d); + prepareDeployment(d); // Global deployment has been injected. skipPrepare = true; @@ -233,16 +232,16 @@ protected final void prepareObject(@Nullable Object o, GridCacheSharedContext ct ClassLoader ldr = U.detectClassLoader(cls); if (ldr instanceof GridDeploymentInfo) - prepare((GridDeploymentInfo)ldr); + prepareDeployment((GridDeploymentInfo)ldr); } } } /** * @param depInfo Deployment to set. - * @see GridCacheDeployable#prepare(GridDeploymentInfo) + * @see GridCacheDeployable#prepareDeployment(GridDeploymentInfo) */ - public final void prepare(GridDeploymentInfo depInfo) { + public final void prepareDeployment(GridDeploymentInfo depInfo) { if (depInfo != this.depInfo) { if (this.depInfo != null && depInfo instanceof GridDeployment) // Make sure not to replace remote deployment with local. @@ -269,13 +268,13 @@ public GridDeploymentInfoBean deployInfo() { * @param ctx Cache context. * @throws IgniteCheckedException If failed. */ - public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { + public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { // No-op. } /** * This method is called after the message is deserialized and is responsible for - * unmarshalling state marshalled in {@link #prepareMarshal(GridCacheSharedContext)} method. + * unmarshalling state marshalled in {@link #prepareDeployment(GridCacheSharedContext)} method. * * @param ctx Context. * @param ldr Class loader. @@ -291,25 +290,23 @@ public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) t * @param cacheObjCtx Cache object context. * @throws IgniteCheckedException If failed. */ - protected final void marshalInfo(GridCacheEntryInfo info, + protected final void prepareInfoDeployment(GridCacheEntryInfo info, GridCacheSharedContext ctx, CacheObjectContext cacheObjCtx ) throws IgniteCheckedException { assert ctx != null; if (info != null) { - info.marshal(cacheObjCtx); - if (addDepInfo) { if (info.key() != null) - prepareObject(info.key().value(cacheObjCtx, false), ctx); + prepareObjectDeployment(info.key().value(cacheObjCtx, false), ctx); CacheObject val = info.value(); if (val != null) { val.finishUnmarshal(cacheObjCtx, ctx.deploy().globalLoader()); - prepareObject(val.value(cacheObjCtx, false), ctx); + prepareObjectDeployment(val.value(cacheObjCtx, false), ctx); } } } @@ -335,7 +332,7 @@ protected final void unmarshalInfo(GridCacheEntryInfo info, GridCacheContext ctx * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void marshalInfos( + protected final void prepareInfosDeployment( Iterable infos, GridCacheSharedContext ctx, CacheObjectContext cacheObjCtx @@ -344,7 +341,7 @@ protected final void marshalInfos( if (infos != null) for (GridCacheEntryInfo e : infos) - marshalInfo(e, ctx, cacheObjCtx); + prepareInfoDeployment(e, ctx, cacheObjCtx); } /** @@ -368,29 +365,26 @@ protected final void unmarshalInfos(Iterable infos * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void marshalTx(Iterable txEntries, GridCacheSharedContext ctx) + protected final void prepareTxDeployment(Iterable txEntries, GridCacheSharedContext ctx) throws IgniteCheckedException { assert ctx != null; if (txEntries != null) { - boolean transferExpiry = transferExpiryPolicy(); boolean p2pEnabled = ctx.deploymentEnabled(); for (IgniteTxEntry e : txEntries) { - e.marshal(ctx, transferExpiry); - GridCacheContext cctx = e.context(); if (addDepInfo) { if (e.key() != null) - prepareObject(e.key().value(cctx.cacheObjectContext(), false), ctx); + prepareObjectDeployment(e.key().value(cctx.cacheObjectContext(), false), ctx); if (e.value() != null) - prepareObject(e.value().value(cctx.cacheObjectContext(), false), ctx); + prepareObjectDeployment(e.value().value(cctx.cacheObjectContext(), false), ctx); if (e.entryProcessors() != null) { for (T2, Object[]> entProc : e.entryProcessors()) - prepareObject(entProc.get1(), ctx); + prepareObjectDeployment(entProc.get1(), ctx); } } else if (p2pEnabled && e.entryProcessors() != null) { @@ -398,19 +392,12 @@ else if (p2pEnabled && e.entryProcessors() != null) { forceAddDepInfo = true; for (T2, Object[]> entProc : e.entryProcessors()) - prepareObject(entProc.get1(), ctx); + prepareObjectDeployment(entProc.get1(), ctx); } } } } - /** - * @return {@code True} if entries expire policy should be marshalled. - */ - protected boolean transferExpiryPolicy() { - return false; - } - /** * @param txEntries Entries to unmarshal. * @param ctx Context. @@ -434,13 +421,12 @@ protected final void unmarshalTx(Iterable txEntries, /** * @param args Arguments to marshal. - * @param ctx Context. + * @param marsh Marshaller. * @return Marshalled collection. * @throws IgniteCheckedException If failed. */ - @Nullable protected final byte[][] marshalInvokeArguments(@Nullable Object[] args, GridCacheContext ctx) + @Nullable protected final byte[][] marshallInvokeArguments(@Nullable Object[] args, Marshaller marsh) throws IgniteCheckedException { - assert ctx != null; if (args == null || args.length == 0) return null; @@ -450,15 +436,31 @@ protected final void unmarshalTx(Iterable txEntries, for (int i = 0; i < args.length; i++) { Object arg = args[i]; - if (addDepInfo) - prepareObject(arg, ctx.shared()); - - argsBytes[i] = arg == null ? null : CU.marshal(ctx, arg); + argsBytes[i] = arg == null ? null : U.marshal(marsh, arg); } return argsBytes; } + /** + * @param args Arguments to marshal. + * @param ctx Context. + * @throws IgniteCheckedException If failed. + */ + @Nullable protected final void prepareInvokeArgumentsDeployment(@Nullable Object[] args, GridCacheContext ctx) + throws IgniteCheckedException { + assert ctx != null; + + if (args == null) + return; + + for (int i = 0; i < args.length; i++) { + Object arg = args[i]; + + if (addDepInfo) + prepareObjectDeployment(arg, ctx.shared()); + } + } /** * @param byteCol Collection to unmarshal. @@ -488,27 +490,35 @@ protected final void unmarshalTx(Iterable txEntries, /** * @param col Collection to marshal. - * @param ctx Context. + * @param marsh Marshaller. * @return Marshalled collection. * @throws IgniteCheckedException If failed. */ - @Nullable protected List marshalCollection(@Nullable Collection col, - GridCacheContext ctx) throws IgniteCheckedException { - assert ctx != null; - + @Nullable protected List marshallCollection(@Nullable Collection col, Marshaller marsh) throws IgniteCheckedException { if (col == null) return null; List byteCol = new ArrayList<>(col.size()); + for (Object o : col) + byteCol.add(o == null ? null : U.marshal(marsh, o)); + + return byteCol; + } + + /** + * @param col Collection to marshal. + * @param ctx Context. + * @throws IgniteCheckedException If failed. + */ + @Nullable protected void prepareCollectionDeployment(@Nullable Collection col, + GridCacheContext ctx) throws IgniteCheckedException { + assert ctx != null; + for (Object o : col) { if (addDepInfo) - prepareObject(o, ctx.shared()); - - byteCol.add(o == null ? null : CU.marshal(ctx, o)); + prepareObjectDeployment(o, ctx.shared()); } - - return byteCol; } /** @@ -517,7 +527,7 @@ protected final void unmarshalTx(Iterable txEntries, * @throws IgniteCheckedException If failed. */ @SuppressWarnings("ForLoopReplaceableByForEach") - public final void prepareMarshalCacheObjects(@Nullable List col, + public final void prepareCacheObjectsDeployment(@Nullable List col, GridCacheContext ctx) throws IgniteCheckedException { if (col == null) return; @@ -525,7 +535,7 @@ public final void prepareMarshalCacheObjects(@Nullable List col, + protected final void prepareCacheObjectsDeployment(@Nullable Collection col, GridCacheContext ctx) throws IgniteCheckedException { if (col == null) return; for (CacheObject obj : col) { if (obj != null) { - obj.prepareMarshal(ctx.cacheObjectContext()); - if (addDepInfo) - prepareObject(obj.value(ctx.cacheObjectContext(), false), ctx.shared()); + prepareObjectDeployment(obj.value(ctx.cacheObjectContext(), false), ctx.shared()); } } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java index 7c78a10a5cf48..2ca5fa2376f4e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java @@ -31,13 +31,14 @@ import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; import org.apache.ignite.plugin.extensions.communication.Message; import org.jetbrains.annotations.Nullable; /** * Return value for cases where both, value and success flag need to be returned. */ -public class GridCacheReturn implements Message { +public class GridCacheReturn implements Message, CacheIdAware { /** Value. */ @GridToStringInclude(sensitive = true) private volatile Object v; @@ -285,10 +286,8 @@ else if (err instanceof UnregisteredBinaryTypeException) } } - /** - * @return Cache ID. - */ - public int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } @@ -328,22 +327,6 @@ public void marshalResult(GridCacheContext ctx) { } } - /** - * @param ctx Cache context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { - assert !loc; - - if (cacheObj != null) - cacheObj.prepareMarshal(ctx.cacheObjectContext()); - - if (invokeRes && invokeResCol != null) { - for (CacheInvokeDirectResult res : invokeResCol) - res.prepareMarshal(ctx); - } - } - /** * @param ctx Cache context. * @param ldr Class loader. 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 c83e732f6181a..1dff6dd3fe341 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 @@ -156,14 +156,14 @@ public List nearVersions() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); - prepareMarshalCacheObjects(nearKeys, cctx); + prepareCacheObjectsDeployment(nearKeys, cctx); } /** {@inheritDoc} */ 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 b02d75024fec5..7616318ed7336 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 @@ -348,12 +348,12 @@ public long timeout() { /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); } /** {@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 cbf10745a7a19..c9f2fb14ebc17 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 @@ -161,10 +161,10 @@ protected int valuesSize() { /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); - prepareMarshalCacheObjects(vals, ctx.cacheContext(cacheId)); + prepareCacheObjectsDeployment(vals, ctx.cacheContext(cacheId)); } /** {@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 bd427bd47b56f..958da951dc386 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 @@ -25,8 +25,8 @@ import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry; @@ -38,6 +38,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; import org.jetbrains.annotations.Nullable; @@ -46,7 +47,7 @@ * Transaction prepare request for optimistic and eventually consistent * transactions. */ -public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage implements IgniteTxStateAware { +public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage implements IgniteTxStateAware, MarshallableMessage { /** */ private static final int NEED_RETURN_VALUE_FLAG_MASK = 0x01; @@ -372,25 +373,14 @@ public void applicationAttributes(Map appAttrs) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); if (writes != null) - marshalTx(writes, ctx); + prepareTxDeployment(writes, ctx); if (reads != null) - marshalTx(reads, ctx); - - if (dhtVers != null && dhtVerKeys == null) { - for (IgniteTxKey key : dhtVers.keySet()) { - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - - key.prepareMarshal(cctx); - } - - dhtVerKeys = dhtVers.keySet(); - dhtVerVals = dhtVers.values(); - } + prepareTxDeployment(reads, ctx); } /** {@inheritDoc} */ @@ -452,6 +442,18 @@ private boolean isFlag(int mask) { return (flags & mask) != 0; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (dhtVers != null && dhtVerKeys == null) { + dhtVerKeys = dhtVers.keySet(); + dhtVerVals = dhtVers.values(); + } + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridNearUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridNearUnlockRequest.java index 7f46f96774850..78086afad7bc9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridNearUnlockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridNearUnlockRequest.java @@ -95,10 +95,10 @@ public void addKey(KeyCacheObject key) { /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); - prepareMarshalCacheObjects(keys, ctx.cacheContext(cacheId)); + prepareCacheObjectsDeployment(keys, ctx.cacheContext(cacheId)); } /** {@inheritDoc} */ 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 7277db3ccd698..ec2e09483c0d1 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 @@ -1214,9 +1214,9 @@ protected void processNearSingleGetRequest(final UUID nodeId, final GridNearSing res0 = info; } else if (req.needVersion()) - res0 = new CacheVersionedValue(info.value(), info.version()); + res0 = new CacheVersionedValue(info.value(), info.version(), info.cacheId()); else - res0 = new CacheVersionedValue(info.value(), null); + res0 = new CacheVersionedValue(info.value(), null, info.cacheId()); } res = new GridNearSingleGetResponse( 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 315997cecd8a6..f771d635dedb7 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 @@ -21,6 +21,7 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; @@ -32,6 +33,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.marshaller.Marshaller; import org.apache.ignite.transactions.TransactionIsolation; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,7 +41,7 @@ /** * DHT lock request. */ -public class GridDhtLockRequest extends GridDistributedLockRequest { +public class GridDhtLockRequest extends GridDistributedLockRequest implements MarshallableMessage { /** Invalidate reader flags. */ @Order(0) BitSet invalidateEntries; @@ -257,9 +259,24 @@ public long accessTtl() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { + super.finishUnmarshal(ctx, ldr); + + if (ownedKeys != null) { + owned = new GridLeanMap<>(ownedKeys.length); + + for (int i = 0; i < ownedKeys.length; i++) { + ownedKeys[i].finishUnmarshal(ctx.cacheContext(cacheId).cacheObjectContext(), ldr); + owned.put(ownedKeys[i], ownedValues[i]); + } + + ownedKeys = null; + ownedValues = null; + } + } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { if (owned != null && ownedKeys == null) { ownedKeys = new KeyCacheObject[owned.size()]; ownedValues = new GridCacheVersion[ownedKeys.length]; @@ -275,23 +292,10 @@ public long accessTtl() { } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (ownedKeys != null) { - owned = new GridLeanMap<>(ownedKeys.length); + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { - for (int i = 0; i < ownedKeys.length; i++) { - ownedKeys[i].finishUnmarshal(ctx.cacheContext(cacheId).cacheObjectContext(), ldr); - owned.put(ownedKeys[i], ownedValues[i]); - } - - ownedKeys = null; - ownedValues = null; - } } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtLockRequest.class, this, "super", super.toString()); 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 e73f606c827eb..1a2690b843cc2 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 @@ -124,13 +124,13 @@ public Collection preloadEntries() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (preloadEntries != null) - marshalInfos(preloadEntries, cctx.shared(), cctx.cacheObjectContext()); + prepareInfosDeployment(preloadEntries, cctx.shared(), cctx.cacheObjectContext()); } /** {@inheritDoc} */ 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 352281f9b57c8..4225fffcfb22b 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 @@ -118,19 +118,6 @@ public boolean checkCommitted() { return checkCommitted; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (retVal != null && retVal.cacheId() != 0) { - GridCacheContext cctx = ctx.cacheContext(retVal.cacheId()); - - assert cctx != null : retVal.cacheId(); - - retVal.prepareMarshal(cctx); - } - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { 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 f8364dca6adb1..76a81ea00f0ee 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 @@ -26,6 +26,7 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -39,12 +40,13 @@ import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.Nullable; /** * DHT prepare request. */ -public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest { +public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest implements MarshallableMessage { /** Max order. */ @Order(0) UUID nearNodeId; @@ -320,26 +322,20 @@ public boolean skipCompletedVersion() { * * @param ctx */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); if (owned != null && ownedKeys == null) { - ownedKeys = owned.keySet(); - - ownedVals = owned.values(); - - for (IgniteTxKey key: ownedKeys) { + for (IgniteTxKey key: owned.keySet()) { GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - key.prepareMarshal(cctx); - if (addDepInfo) - prepareObject(key, cctx); + prepareObjectDeployment(key, cctx); } } if (nearWrites != null) - marshalTx(nearWrites, ctx); + prepareTxDeployment(nearWrites, ctx); } /** {@inheritDoc} */ @@ -391,7 +387,20 @@ public boolean skipCompletedVersion() { } } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (owned != null && ownedKeys == null) { + ownedKeys = owned.keySet(); + ownedVals = owned.values(); + } + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } + /** {@inheritDoc} */ @Override public int partition() { return U.safeAbs(version().hashCode()); 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 921f52790252b..af5577fb03881 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 @@ -169,29 +169,6 @@ public void addPreloadEntry(GridCacheEntryInfo info) { preloadEntries.add(info); } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (nearEvicted != null) { - for (IgniteTxKey key : nearEvicted) { - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - - // Can be null if client near cache was removed, in this case assume do not need prepareMarshal. - if (cctx != null) - key.prepareMarshal(cctx); - } - } - - if (preloadEntries != null) { - for (GridCacheEntryInfo info : preloadEntries) { - GridCacheContext cctx = ctx.cacheContext(info.cacheId()); - - info.marshal(cctx); - } - } - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { super.finishUnmarshal(ctx, ldr); 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 8c5fc051a69e7..c8677d3e2720c 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 @@ -71,10 +71,10 @@ public void addNearKey(KeyCacheObject key) } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); - prepareMarshalCacheObjects(nearKeys, ctx.cacheContext(cacheId)); + prepareCacheObjectsDeployment(nearKeys, ctx.cacheContext(cacheId)); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/TransactionAttributesAwareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/TransactionAttributesAwareRequest.java index 4cc026c390cda..36b7a66ea4f7e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/TransactionAttributesAwareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/TransactionAttributesAwareRequest.java @@ -58,8 +58,8 @@ public Map applicationAttributes() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - payload.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + payload.prepareDeployment(ctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicApplicationAttributesAwareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicApplicationAttributesAwareRequest.java index 7c37b474dd2b7..238a65b7ff3dd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicApplicationAttributesAwareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicApplicationAttributesAwareRequest.java @@ -58,8 +58,8 @@ public Map applicationAttributes() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - payload.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + payload.prepareDeployment(ctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java index f71e035bdac94..bdb7717e85bf8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java @@ -171,14 +171,6 @@ public long futureId() { return false; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (errs != null) - errs.prepareMarshal(this, ctx.cacheContext(cacheId)); - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { super.finishUnmarshal(ctx, ldr); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicSingleUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicSingleUpdateRequest.java index 20aad2f7dec8b..907934555ade5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicSingleUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicSingleUpdateRequest.java @@ -311,19 +311,6 @@ private void near(boolean near) { return null; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - prepareMarshalObject(key, cctx); - - prepareMarshalObject(val, cctx); - - prepareMarshalObject(prevVal, cctx); - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { super.finishUnmarshal(ctx, ldr); @@ -337,16 +324,6 @@ private void near(boolean near) { finishUnmarshalObject(prevVal, cctx, ldr); } - /** - * @param obj CacheObject to marshal - * @param ctx context - * @throws IgniteCheckedException if error - */ - private void prepareMarshalObject(CacheObject obj, GridCacheContext ctx) throws IgniteCheckedException { - if (obj != null) - obj.prepareMarshal(ctx.cacheObjectContext()); - } - /** * @param obj CacheObject un to marshal * @param ctx context 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 4d06d1705daaf..d589c46f90dd3 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,6 +23,7 @@ import java.util.UUID; import javax.cache.processor.EntryProcessor; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; @@ -36,13 +37,14 @@ import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * Lite dht cache backup update request. */ -public class GridDhtAtomicUpdateRequest extends GridDhtAtomicAbstractUpdateRequest { +public class GridDhtAtomicUpdateRequest extends GridDhtAtomicAbstractUpdateRequest implements MarshallableMessage { /** Keys to update. */ @GridToStringInclude @Order(0) @@ -462,20 +464,20 @@ else if (conflictVers != null) } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); - prepareMarshalCacheObjects(vals, cctx); + prepareCacheObjectsDeployment(vals, cctx); - prepareMarshalCacheObjects(nearKeys, cctx); + prepareCacheObjectsDeployment(nearKeys, cctx); - prepareMarshalCacheObjects(nearVals, cctx); + prepareCacheObjectsDeployment(nearVals, cctx); - prepareMarshalCacheObjects(prevVals, cctx); + prepareCacheObjectsDeployment(prevVals, cctx); if (forceTransformBackups) { // force addition of deployment info for entry processors if P2P is enabled globally. @@ -483,13 +485,13 @@ else if (conflictVers != null) addDepInfo = true; if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) - invokeArgsBytes = Arrays.asList(marshalInvokeArguments(invokeArgs, cctx)); + prepareInvokeArgumentsDeployment(invokeArgs, cctx); if (entryProcessorsBytes == null) - entryProcessorsBytes = marshalCollection(entryProcessors, cctx); + prepareCollectionDeployment(entryProcessors, cctx); if (nearEntryProcessorsBytes == null) - nearEntryProcessorsBytes = marshalCollection(nearEntryProcessors, cctx); + prepareCollectionDeployment(nearEntryProcessors, cctx); } } @@ -527,6 +529,24 @@ else if (conflictVers != null) prevVals = null; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (forceTransformBackups) { + if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) + invokeArgsBytes = Arrays.asList(marshallInvokeArguments(invokeArgs, marsh)); + + if (entryProcessorsBytes == null) + entryProcessorsBytes = marshallCollection(entryProcessors, marsh); + + if (nearEntryProcessorsBytes == null) + nearEntryProcessorsBytes = marshallCollection(nearEntryProcessors, marsh); + } + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } /** {@inheritDoc} */ @Override public String toString() { 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 a63354bc634fa..9bab174411736 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 @@ -119,18 +119,14 @@ public void nearEvicted(List nearEvicted) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); // Can be null if client near cache was removed, in this case assume do not need prepareMarshal. - if (cctx != null) { - prepareMarshalCacheObjects(nearEvicted, cctx); - - if (errs != null) - errs.prepareMarshal(this, cctx); - } + if (cctx != null) + prepareCacheObjectsDeployment(nearEvicted, cctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicFullUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicFullUpdateRequest.java index 62fcf3966d916..5082d1c25160d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicFullUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicFullUpdateRequest.java @@ -25,6 +25,7 @@ import javax.cache.processor.EntryProcessor; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; @@ -41,6 +42,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,7 +53,7 @@ /** * Lite DHT cache update request sent from near node to primary node. */ -public class GridNearAtomicFullUpdateRequest extends GridNearAtomicAbstractUpdateRequest { +public class GridNearAtomicFullUpdateRequest extends GridNearAtomicAbstractUpdateRequest implements MarshallableMessage { /** Keys to update. */ @Order(0) @GridToStringInclude @@ -328,30 +330,18 @@ else if (conflictVers != null) } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (expiryPlc != null && expiryPlcBytes == null) expiryPlcBytes = CU.marshal(cctx, new IgniteExternalizableExpiryPolicy(expiryPlc)); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); - if (filter != null) { - boolean hasFilter = false; - - for (CacheEntryPredicate p : filter) { - if (p != null) { - hasFilter = true; - - p.prepareMarshal(cctx); - } - } - - if (!hasFilter) - filter = null; - } + if (filter != null && filter.length == 0) + filter = null; if (operation() == TRANSFORM) { // force addition of deployment info for entry processors if P2P is enabled globally. @@ -359,13 +349,13 @@ else if (conflictVers != null) addDepInfo = true; if (entryProcessorsBytes == null) - entryProcessorsBytes = marshalCollection(entryProcessors, cctx); + prepareCollectionDeployment(entryProcessors, cctx); if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) - invokeArgsBytes = Arrays.asList(marshalInvokeArguments(invokeArgs, cctx)); + prepareInvokeArgumentsDeployment(invokeArgs, cctx); } else - prepareMarshalCacheObjects(vals, cctx); + prepareCacheObjectsDeployment(vals, cctx); } /** {@inheritDoc} */ @@ -416,6 +406,21 @@ else if (conflictVers != null) keys = null; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (operation() == TRANSFORM) { + if (entryProcessorsBytes == null) + entryProcessorsBytes = marshallCollection(entryProcessors, marsh); + + if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) + invokeArgsBytes = Arrays.asList(marshallInvokeArguments(invokeArgs, marsh)); + } + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFilterRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFilterRequest.java index 7b072491d4f89..9555f9a475ff5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFilterRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFilterRequest.java @@ -21,6 +21,7 @@ import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; @@ -28,13 +29,14 @@ import org.apache.ignite.internal.processors.cache.GridCacheOperation; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * */ -public class GridNearAtomicSingleUpdateFilterRequest extends GridNearAtomicSingleUpdateRequest { +public class GridNearAtomicSingleUpdateFilterRequest extends GridNearAtomicSingleUpdateRequest implements MarshallableMessage { /** Filter. */ @Order(0) CacheEntryPredicate[] filter; @@ -91,28 +93,6 @@ public GridNearAtomicSingleUpdateFilterRequest() { return filter; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - if (filter != null) { - boolean hasFilter = false; - - for (CacheEntryPredicate p : filter) { - if (p != null) { - hasFilter = true; - - p.prepareMarshal(cctx); - } - } - - if (!hasFilter) - filter = null; - } - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { super.finishUnmarshal(ctx, ldr); @@ -127,6 +107,16 @@ public GridNearAtomicSingleUpdateFilterRequest() { } } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (filter != null && filter.length == 0) + filter = null; + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateInvokeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateInvokeRequest.java index 2b2e44f5e7ea7..afe5ed3d0ecb1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateInvokeRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateInvokeRequest.java @@ -24,6 +24,7 @@ import javax.cache.processor.EntryProcessor; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; @@ -33,9 +34,9 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,7 +45,7 @@ /** * */ -public class GridNearAtomicSingleUpdateInvokeRequest extends GridNearAtomicSingleUpdateRequest { +public class GridNearAtomicSingleUpdateInvokeRequest extends GridNearAtomicSingleUpdateRequest implements MarshallableMessage { /** Optional arguments for entry processor. */ private @Nullable Object[] invokeArgs; @@ -160,8 +161,8 @@ public GridNearAtomicSingleUpdateInvokeRequest() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); @@ -171,13 +172,11 @@ public GridNearAtomicSingleUpdateInvokeRequest() { if (entryProc != null && entryProcBytes == null) { if (addDepInfo) - prepareObject(entryProc, cctx); - - entryProcBytes = CU.marshal(cctx, entryProc); + prepareObjectDeployment(entryProc, cctx); } if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) - invokeArgsBytes = Arrays.asList(marshalInvokeArguments(invokeArgs, cctx)); + prepareInvokeArgumentsDeployment(invokeArgs, cctx); } /** {@inheritDoc} */ @@ -198,6 +197,19 @@ public GridNearAtomicSingleUpdateInvokeRequest() { entryProc = null; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (entryProc != null && entryProcBytes == null) + entryProcBytes = U.marshal(marsh, entryProc); + + if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) + invokeArgsBytes = Arrays.asList(marshallInvokeArguments(invokeArgs, marsh)); + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateRequest.java index 25b31b062c7c3..f9428a4497770 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateRequest.java @@ -217,15 +217,15 @@ public GridNearAtomicSingleUpdateRequest() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObject(key, cctx); + prepareCacheObjectDeployment(key, cctx); if (val != null) - prepareMarshalCacheObject(val, cctx); + prepareCacheObjectDeployment(val, cctx); } /** {@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 a1103fb308d55..d42596aedb39e 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 @@ -339,19 +339,13 @@ synchronized void addFailedKeys(Collection keys, Throwable e) { /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - if (errs != null) - errs.prepareMarshal(this, cctx); - if (nearUpdates != null) - prepareMarshalCacheObjects(nearUpdates.nearValues(), cctx); - - if (ret != null) - ret.prepareMarshal(cctx); + prepareCacheObjectsDeployment(nearUpdates.nearValues(), cctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/UpdateErrors.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/UpdateErrors.java index 0e42f82082251..105292b3798d3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/UpdateErrors.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/UpdateErrors.java @@ -117,7 +117,7 @@ void addFailedKeys(Collection keys, Throwable e) { /** */ void prepareMarshal(GridCacheMessage msg, GridCacheContext cctx) throws IgniteCheckedException { - msg.prepareMarshalCacheObjects(failedKeys, cctx); + msg.prepareCacheObjectsDeployment(failedKeys, cctx); } /** */ 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 898ad4478f086..8038375f1e9d0 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 @@ -114,12 +114,12 @@ public Collection keys() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); } /** {@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 cafcb5fa3e364..45e9f1e2f0965 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 @@ -132,18 +132,13 @@ public void addInfo(GridCacheEntryInfo info) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (missedKeys != null) - prepareMarshalCacheObjects(missedKeys, cctx); - - if (infos != null) { - for (GridCacheEntryInfo info : infos) - info.marshal(cctx.cacheObjectContext()); - } + prepareCacheObjectsDeployment(missedKeys, cctx); } /** {@inheritDoc} */ 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 a800ab4d1f7a8..4c90b909c9efb 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 @@ -215,7 +215,7 @@ void addEntry0(int p, boolean historical, GridCacheEntryInfo info, GridCacheShar assert info.value() != null || historical : info; // Need to call this method to initialize info properly. - marshalInfo(info, ctx, cacheObjCtx); + prepareInfoDeployment(info, ctx, cacheObjCtx); msgSize += info.marshalledSize(cacheObjCtx); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java index 733f9b0adc462..0ccb732f850aa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java @@ -3865,7 +3865,7 @@ else if (exchCtx.events().hasServerLeft()) else if (forceAffReassignment) msg.idealAffinityDiff(idealAffDiff); - msg.prepareMarshal(cctx); + msg.prepareDeployment(cctx); timeBag.finishGlobalStage("Full message preparing"); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/CacheVersionedValue.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/CacheVersionedValue.java index af5d90f84d2a2..21d11e1d45393 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/CacheVersionedValue.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/CacheVersionedValue.java @@ -20,17 +20,17 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; import org.apache.ignite.plugin.extensions.communication.Message; /** * Cache object and version. */ -public class CacheVersionedValue implements Message { +public class CacheVersionedValue implements Message, CacheIdAware { /** Value. */ @Order(0) @GridToStringInclude @@ -40,6 +40,9 @@ public class CacheVersionedValue implements Message { @Order(1) @GridToStringInclude GridCacheVersion ver; + + /** */ + private int cacheId; /** */ public CacheVersionedValue() { @@ -50,9 +53,10 @@ public CacheVersionedValue() { * @param val Cache value. * @param ver Cache version. */ - public CacheVersionedValue(CacheObject val, GridCacheVersion ver) { + public CacheVersionedValue(CacheObject val, GridCacheVersion ver, int cacheId) { this.val = val; this.ver = ver; + this.cacheId = cacheId; } /** @@ -69,18 +73,6 @@ public CacheObject value() { return val; } - /** - * This method is called before the whole message is sent - * and is responsible for pre-marshalling state. - * - * @param ctx Cache object context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException { - if (val != null) - val.prepareMarshal(ctx); - } - /** * This method is called after the whole message is received * and is responsible for unmarshalling state. @@ -99,4 +91,9 @@ public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws Ignite @Override public String toString() { return S.toString(CacheVersionedValue.class, this); } + + /** {@inheritDoc} */ + @Override public int cacheId() { + return cacheId; + } } 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 74ad48394405d..c92b4639f5b02 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 @@ -284,8 +284,8 @@ public long accessTtl() { * @param ctx Cache context. * @throws IgniteCheckedException If failed. */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); assert ctx != null; assert !F.isEmpty(keys); @@ -293,7 +293,7 @@ public long accessTtl() { GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); } /** 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 56f0aa1ca803d..61da734a27bec 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 @@ -173,19 +173,6 @@ public void error(@Nullable Throwable err) { errMsg = new ErrorMessage(err); } - /** {@inheritDoc} - * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - if (entries != null) { - for (GridCacheEntryInfo info : entries) - info.marshal(cctx); - } - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { super.finishUnmarshal(ctx, ldr); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java index 07ca1355fc0f0..ded6016b3a5c9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java @@ -250,14 +250,14 @@ public boolean recovery() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); assert key != null; GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObject(key, cctx); + prepareCacheObjectDeployment(key, cctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java index 73f72ec4c0247..28c80f2dc963c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java @@ -145,18 +145,14 @@ public long futureId() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); if (res != null) { GridCacheContext cctx = ctx.cacheContext(cacheId); if (res instanceof CacheObject) - prepareMarshalCacheObject((CacheObject)res, cctx); - else if (res instanceof CacheVersionedValue) - ((CacheVersionedValue)res).prepareMarshal(cctx.cacheObjectContext()); - else if (res instanceof GridCacheEntryInfo) - ((GridCacheEntryInfo)res).marshal(cctx); + prepareCacheObjectDeployment((CacheObject)res, cctx); } } 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 05b7f6ef918a1..a9ada7e55545a 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 @@ -265,11 +265,6 @@ private Collection cloneEntries(Collection c) { return cp; } - /** {@inheritDoc} */ - @Override protected boolean transferExpiryPolicy() { - return true; - } - /** * Sets flag mask. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java index 646335209b86e..5dffe6ad9d47c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.Map; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; @@ -37,12 +38,13 @@ import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.Nullable; /** * Near cache prepare response. */ -public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse { +public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse implements MarshallableMessage { /** Versions that are less than lock version ({@link #version()}). */ @GridToStringInclude @Order(0) @@ -196,7 +198,7 @@ public void addOwnedValue(IgniteTxKey key, GridCacheVersion ver, CacheObject val if (ownedVals == null) ownedVals = new HashMap<>(); - CacheVersionedValue oVal = new CacheVersionedValue(val, ver); + CacheVersionedValue oVal = new CacheVersionedValue(val, ver, key.cacheId()); ownedVals.put(key, oVal); } @@ -235,46 +237,6 @@ public boolean hasOwnedValue(IgniteTxKey key) { return F.mapContainsKey(ownedVals, key); } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - // There are separate collections for keys and values of the 'ownedVals' map, because IgniteTxKey - // can not be inserted directly in a map as a key during invocation of MessageReader#read. - // The IgniteTxKey's hash code calculation will fail due to delegation of calculation - // to KeyCacheObjectImpl#hashCode, which in turn fails with assertion error if KeyCacheObjectImpl#val - // has not initialized yet in KeyCacheObjectImpl#finishUnmarshal. - if (ownedVals != null && ownedValKeys == null) { - ownedValKeys = ownedVals.keySet(); - - ownedValVals = ownedVals.values(); - - for (Map.Entry entry : ownedVals.entrySet()) { - GridCacheContext cacheCtx = ctx.cacheContext(entry.getKey().cacheId()); - - entry.getKey().prepareMarshal(cacheCtx); - - entry.getValue().prepareMarshal(cacheCtx.cacheObjectContext()); - } - } - - if (retVal != null && retVal.cacheId() != 0) { - GridCacheContext cctx = ctx.cacheContext(retVal.cacheId()); - - assert cctx != null : retVal.cacheId(); - - retVal.prepareMarshal(cctx); - } - - if (filterFailedKeys != null) { - for (IgniteTxKey key : filterFailedKeys) { - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - - key.prepareMarshal(cctx); - } - } - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { super.finishUnmarshal(ctx, ldr); @@ -325,7 +287,20 @@ public boolean hasOwnedValue(IgniteTxKey key) { } } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (ownedVals != null && ownedValKeys == null) { + ownedValKeys = ownedVals.keySet(); + + ownedValVals = ownedVals.values(); + } + } + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridNearTxPrepareResponse.class, this, "super", super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotAwareMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotAwareMessage.java index 5a0824c9a5d41..1032504d60ad5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotAwareMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotAwareMessage.java @@ -82,8 +82,8 @@ public long snapshotTopologyVersion() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - payload.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + payload.prepareDeployment(ctx); } /** {@inheritDoc} */ 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 84813c40420c9..5e1fba2884fbe 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 @@ -19,6 +19,7 @@ import java.util.Collection; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObjectContext; @@ -29,7 +30,6 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiPredicate; @@ -45,7 +45,7 @@ /** * Query request. */ -public class GridCacheQueryRequest extends GridCacheIdMessage implements GridCacheDeployable { +public class GridCacheQueryRequest extends GridCacheIdMessage implements GridCacheDeployable, MarshallableMessage { /** */ private static final int FLAG_DATA_PAGE_SCAN_DFLT = 0b00; @@ -407,51 +407,36 @@ private static byte setDataPageScanEnabled(int flags, Boolean enabled) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (keyValFilter != null && keyValFilterBytes == null) { if (addDepInfo) - prepareObject(keyValFilter, cctx); - - keyValFilterBytes = CU.marshal(cctx, keyValFilter); + prepareObjectDeployment(keyValFilter, cctx); } if (rdc != null && rdcBytes == null) { if (addDepInfo) - prepareObject(rdc, cctx); - - rdcBytes = CU.marshal(cctx, rdc); + prepareObjectDeployment(rdc, cctx); } if (trans != null && transBytes == null) { if (addDepInfo) - prepareObject(trans, cctx); - - transBytes = CU.marshal(cctx, trans); + prepareObjectDeployment(trans, cctx); } if (!F.isEmpty(args) && argsBytes == null) { if (addDepInfo) { for (Object arg : args) - prepareObject(arg, cctx); + prepareObjectDeployment(arg, cctx); } - - argsBytes = CU.marshal(cctx, args); } if (idxQryDesc != null && idxQryDescBytes == null) { if (addDepInfo) - prepareObject(idxQryDesc, cctx); - - idxQryDescBytes = CU.marshal(cctx, idxQryDesc); - } - - if (!F.isEmpty(skipKeys)) { - for (KeyCacheObject k : skipKeys) - k.prepareMarshal(cctx.cacheObjectContext()); + prepareObjectDeployment(idxQryDesc, cctx); } } @@ -659,6 +644,28 @@ public Collection skipKeys() { return part; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (keyValFilter != null && keyValFilterBytes == null) + keyValFilterBytes = U.marshal(marsh, keyValFilter); + + if (rdc != null && rdcBytes == null) + rdcBytes = U.marshal(marsh, rdc); + + if (trans != null && transBytes == null) + transBytes = U.marshal(marsh, trans); + + if (!F.isEmpty(args) && argsBytes == null) + argsBytes = U.marshal(marsh, args); + + if (idxQryDesc != null && idxQryDescBytes == null) + idxQryDescBytes = U.marshal(marsh, idxQryDesc); + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } /** {@inheritDoc} */ @Override public String toString() { 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 6b295f2561182..78dcd963c55f7 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 @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.cache.query.index.IndexQueryResultMeta; import org.apache.ignite.internal.managers.communication.ErrorMessage; @@ -40,7 +41,7 @@ /** * Page of cache query response. */ -public class GridCacheQueryResponse extends GridCacheIdMessage implements GridCacheDeployable { +public class GridCacheQueryResponse extends GridCacheIdMessage implements GridCacheDeployable, MarshallableMessage { /** */ @Order(0) boolean finished; @@ -105,21 +106,21 @@ public GridCacheQueryResponse(int cacheId, long reqId, Throwable err, boolean ad /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (dataBytes == null && data != null) - dataBytes = marshalCollection(data, cctx); + prepareCollectionDeployment(data, cctx); if (addDepInfo && !F.isEmpty(data)) { for (Object o : data) { if (o instanceof Map.Entry) { Map.Entry e = (Map.Entry)o; - prepareObject(e.getKey(), cctx); - prepareObject(e.getValue(), cctx); + prepareObjectDeployment(e.getKey(), cctx); + prepareObjectDeployment(e.getValue(), cctx); } } } @@ -233,6 +234,16 @@ public boolean fields() { return fields; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (dataBytes == null && data != null) + dataBytes = marshallCollection(data, marsh); + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java index 130dcec622821..9acf37ef7a23d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java @@ -19,7 +19,6 @@ import javax.cache.event.EventType; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.deployment.GridDeploymentInfo; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; @@ -30,13 +29,14 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; +import org.apache.ignite.plugin.extensions.communication.Message; import org.jetbrains.annotations.Nullable; /** * Continuous query entry. */ -public class CacheContinuousQueryEntry implements GridCacheDeployable, MarshallableMessage { +public class CacheContinuousQueryEntry implements GridCacheDeployable, Message, CacheIdAware { /** */ private static final byte BACKUP_ENTRY = 0b0001; @@ -56,27 +56,18 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Marshalla /** Key. */ @GridToStringInclude - KeyCacheObject key; - - /** */ @Order(2) - byte[] keyBytes; + KeyCacheObject key; /** New value. */ @GridToStringInclude - CacheObject newVal; - - /** */ @Order(3) - byte[] newValBytes; + CacheObject newVal; /** Old value. */ @GridToStringInclude - CacheObject oldVal; - - /** */ @Order(4) - byte[] oldValBytes; + CacheObject oldVal; /** Cache name. */ @Order(5) @@ -194,10 +185,8 @@ public byte flags() { return topVer; } - /** - * @return Cache ID. - */ - int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } @@ -235,6 +224,9 @@ void markBackup() { void markFiltered() { flags |= FILTERED_ENTRY; depInfo = null; + key = null; + newVal = null; + oldVal = null; } /** @@ -295,21 +287,6 @@ boolean isKeepBinary() { return (flags & KEEP_BINARY) != 0; } - /** - * @param cctx Cache context. - * @throws IgniteCheckedException In case of error. - */ - void prepareMarshal(GridCacheContext cctx) throws IgniteCheckedException { - if (key != null) - key.prepareMarshal(cctx.cacheObjectContext()); - - if (newVal != null) - newVal.prepareMarshal(cctx.cacheObjectContext()); - - if (oldVal != null) - oldVal.prepareMarshal(cctx.cacheObjectContext()); - } - /** * @param cctx Cache context. * @param ldr Class loader. @@ -350,7 +327,7 @@ CacheObject oldValue() { } /** {@inheritDoc} */ - @Override public void prepare(GridDeploymentInfo depInfo) { + @Override public void prepareDeployment(GridDeploymentInfo depInfo) { this.depInfo = depInfo; } @@ -364,30 +341,4 @@ CacheObject oldValue() { @Override public String toString() { return S.toString(CacheContinuousQueryEntry.class, this); } - - /** {@inheritDoc} */ - @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { - if (!isFiltered()) { - if (key != null) - keyBytes = marsh.marshal(key); - - if (newVal != null) - newValBytes = marsh.marshal(newVal); - - if (oldVal != null) - oldValBytes = marsh.marshal(oldVal); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { - if (keyBytes != null) - key = marsh.unmarshal(keyBytes, clsLdr); - - if (newValBytes != null) - newVal = marsh.unmarshal(newValBytes, clsLdr); - - if (oldValBytes != null) - oldVal = marsh.unmarshal(oldValBytes, clsLdr); - } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java index 200a40cb796d1..902b418f64fe3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java @@ -928,13 +928,8 @@ protected CacheEntryEventFilter getEventFilter0() { */ private void prepareEntry(GridCacheContext cctx, UUID nodeId, CacheContinuousQueryEntry entry) throws IgniteCheckedException { - if (cctx.kernalContext().config().isPeerClassLoadingEnabled() && cctx.discovery().node(nodeId) != null) { - entry.prepareMarshal(cctx); - + if (cctx.kernalContext().config().isPeerClassLoadingEnabled() && cctx.discovery().node(nodeId) != null) cctx.deploy().prepare(entry); - } - else - entry.prepareMarshal(cctx); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java index c4f024b2d25b0..c6949c52e249c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java @@ -25,6 +25,7 @@ import javax.cache.processor.EntryProcessor; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; @@ -47,7 +48,8 @@ import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; import org.apache.ignite.thread.IgniteThread; import org.jetbrains.annotations.Nullable; @@ -59,7 +61,7 @@ * {@link #equals(Object)} method, as transaction entries should use referential * equality. */ -public class IgniteTxEntry implements GridPeerDeployAware, Message { +public class IgniteTxEntry implements GridPeerDeployAware, MarshallableMessage, CacheIdAware { /** */ private static final long serialVersionUID = 0L; @@ -588,7 +590,7 @@ public KeyCacheObject key() { /** * @return Cache ID. */ - public int cacheId() { + @Override public int cacheId() { return cacheId; } @@ -1021,39 +1023,24 @@ public void filtersSet(boolean filtersSet) { this.filtersSet = filtersSet; } - /** - * @param ctx Context. - * @param transferExpiry {@code True} if expire policy should be marshalled. - * @throws IgniteCheckedException If failed. - */ - public void marshal(GridCacheSharedContext ctx, boolean transferExpiry) throws IgniteCheckedException { - if (filters != null) { - for (CacheEntryPredicate p : filters) { - if (p != null) - p.prepareMarshal(this.ctx); - } - } - + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { // Do not serialize filters if they are null. if (transformClosBytes == null && entryProcessorsCol != null) - transformClosBytes = CU.marshal(this.ctx, entryProcessorsCol); - - if (transferExpiry) - transferExpiryPlc = expiryPlc != null && expiryPlc != this.ctx.expiry(); + transformClosBytes = U.marshal(marsh, entryProcessorsCol); - key.prepareMarshal(context().cacheObjectContext()); - - val.marshal(context()); + transferExpiryPlc = expiryPlc != null && expiryPlc != ctx.expiry(); if (transferExpiryPlc) { if (expiryPlcBytes == null) - expiryPlcBytes = CU.marshal(this.ctx, new IgniteExternalizableExpiryPolicy(expiryPlc)); + expiryPlcBytes = U.marshal(marsh, new IgniteExternalizableExpiryPolicy(expiryPlc)); } else expiryPlcBytes = null; + } - if (oldVal != null) - oldVal.marshal(context()); + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxKey.java index b50bc340c3ba1..b90e3a4805f05 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxKey.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxKey.java @@ -23,13 +23,14 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; import org.apache.ignite.plugin.extensions.communication.Message; /** * Cache transaction key. This wrapper is needed because same keys may be enlisted in the same transaction * for multiple caches. */ -public class IgniteTxKey implements Message { +public class IgniteTxKey implements Message, CacheIdAware { /** Key. */ @Order(0) @GridToStringInclude(sensitive = true) @@ -65,18 +66,10 @@ public KeyCacheObject key() { /** * @return Cache ID. */ - public int cacheId() { + @Override public int cacheId() { return cacheId; } - /** - * @param ctx Context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { - key.prepareMarshal(ctx.cacheObjectContext()); - } - /** * @param ctx Context. * @param ldr Class loader. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java index cd2704daf9007..9a925d1a4a449 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java @@ -2431,7 +2431,7 @@ void txLocksInfo(UUID nodeId, TxDeadlockFuture fut, Set txKeys) { try { if (!cctx.localNodeId().equals(nodeId)) - req.prepareMarshal(cctx); + req.prepareDeployment(cctx); cctx.gridIO().sendToGridTopic(node, TOPIC_TX, req, SYSTEM_POOL); } @@ -3361,7 +3361,7 @@ private class DeadlockDetectionListener implements GridMessageListener { try { if (!cctx.localNodeId().equals(nodeId)) - res.prepareMarshal(cctx); + res.prepareDeployment(cctx); cctx.gridIO().sendToGridTopic(nodeId, TOPIC_TX, res, SYSTEM_POOL); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryValueHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryValueHolder.java index 98e5830cb3b46..1050b7fa22373 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryValueHolder.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryValueHolder.java @@ -21,7 +21,6 @@ import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheOperation; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -119,15 +118,6 @@ public boolean hasReadValue() { return hasReadVal; } - /** - * @param ctx Cache context. - * @throws IgniteCheckedException If marshaling failed. - */ - public void marshal(GridCacheContext ctx) throws IgniteCheckedException { - if (hasWriteVal && val != null) - val.prepareMarshal(ctx.cacheObjectContext()); - } - /** * @param ctx Cache context. * @param ldr Class loader. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java index 4db908333d72b..dab495aeb2698 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Set; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.GridCacheMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; @@ -28,11 +29,12 @@ import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; /** * Transactions lock list request. */ -public class TxLocksRequest extends GridCacheMessage { +public class TxLocksRequest extends GridCacheMessage implements MarshallableMessage { /** Future ID. */ @Order(0) long futId; @@ -88,21 +90,6 @@ public Collection txKeys() { return addDepInfo; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - txKeysArr = new IgniteTxKey[txKeys.size()]; - - int i = 0; - - for (IgniteTxKey key : txKeys) { - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - - txKeysArr[i++] = key; - } - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { super.finishUnmarshal(ctx, ldr); @@ -118,4 +105,18 @@ public Collection txKeys() { txKeysArr = null; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + txKeysArr = new IgniteTxKey[txKeys.size()]; + + int i = 0; + + for (IgniteTxKey key : txKeys) + txKeysArr[i++] = key; + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java index 8ebbcbddbd031..fe01c2f31967d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.GridCacheMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; @@ -31,11 +32,12 @@ import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; /** * Transactions lock list response. */ -public class TxLocksResponse extends GridCacheMessage { +public class TxLocksResponse extends GridCacheMessage implements MarshallableMessage { /** Future ID. */ @Order(0) long futId; @@ -136,43 +138,6 @@ public void addKey(IgniteTxKey key) { return S.toString(TxLocksResponse.class, this); } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (nearTxKeyLocks != null && !nearTxKeyLocks.isEmpty()) { - int len = nearTxKeyLocks.size(); - - nearTxKeysArr = new IgniteTxKey[len]; - locksArr = (List[])new List[len]; - - int i = 0; - - for (Map.Entry> entry : nearTxKeyLocks.entrySet()) { - IgniteTxKey key = entry.getKey(); - - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - - nearTxKeysArr[i] = key; - locksArr[i] = entry.getValue(); - - i++; - } - } - - if (txKeys != null && !txKeys.isEmpty()) { - txKeysArr = new IgniteTxKey[txKeys.size()]; - - int i = 0; - - for (IgniteTxKey key : txKeys) { - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - - txKeysArr[i++] = key; - } - } - } - /** {@inheritDoc} */ @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { try { @@ -208,4 +173,38 @@ public void addKey(IgniteTxKey key) { } } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (nearTxKeyLocks != null && !nearTxKeyLocks.isEmpty()) { + int len = nearTxKeyLocks.size(); + + nearTxKeysArr = new IgniteTxKey[len]; + locksArr = (List[])new List[len]; + + int i = 0; + + for (Map.Entry> entry : nearTxKeyLocks.entrySet()) { + IgniteTxKey key = entry.getKey(); + + nearTxKeysArr[i] = key; + locksArr[i] = entry.getValue(); + + i++; + } + } + + if (txKeys != null && !txKeys.isEmpty()) { + txKeysArr = new IgniteTxKey[txKeys.size()]; + + int i = 0; + + for (IgniteTxKey key : txKeys) + txKeysArr[i++] = key; + } + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + + } } diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/CacheIdAware.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/CacheIdAware.java new file mode 100644 index 0000000000000..3233d054dd2d8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/CacheIdAware.java @@ -0,0 +1,25 @@ +/* + * 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; +/** */ +public interface CacheIdAware { + /** + * @return Cache ID. + */ + public int cacheId(); +} diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java index 90df0601693c3..069edccd6d4d2 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java @@ -17,9 +17,11 @@ package org.apache.ignite.plugin.extensions.communication; -/** - * Interface for message serialization logic. - */ +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; + +/** Message serialization logic. */ public interface MessageSerializer { /** * Writes this message to provided byte buffer. @@ -38,4 +40,19 @@ public interface MessageSerializer { * @return Whether message was fully read. */ public boolean readFrom(M msg, MessageReader reader); + + /** + * Runs {@code CacheObject.prepareMarshal} for {@code @Order} cache-object fields on the user thread, so the NIO + * worker never does it. Default is a no-op. The caller is responsible for guaranteeing that {@code ctx} is + * non-null when invoking this method; resolution-with-null-skip happens at call sites. + * + * @param msg Message instance. + * @param sctx Shared context. + * @param nested Nested context. + * @throws IgniteCheckedException If marshalling fails. + */ + public default void prepareMarshal(M msg, GridCacheSharedContext sctx, GridCacheContext nested) + throws IgniteCheckedException { + // No-op by default. + } } diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java index b8fc471493069..fc3ba41c21ece 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java @@ -32,6 +32,7 @@ import javax.net.ssl.SSLSocket; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.direct.DirectMessageReader; import org.apache.ignite.internal.direct.DirectMessageWriter; import org.apache.ignite.internal.managers.communication.UnknownMessageException; @@ -238,9 +239,12 @@ public Socket socket() { * @param out Output stream to write serialized message. * @throws IOException If serialization fails. */ - void serializeMessage(Message m, OutputStream out) throws IOException { + void serializeMessage(Message m, OutputStream out) throws IOException, IgniteCheckedException { MessageSerializer msgSer = spi.messageFactory().serializer(m.directType()); + if (msgSer != null) + msgSer.prepareMarshal(m, ((IgniteEx)spi.ignite()).context().cache().context(), null); + msgWriter.reset(); msgWriter.setBuffer(msgBuf); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java index e1e2e38dbbf5c..89fd3aae12c15 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java @@ -340,6 +340,36 @@ public void testCompressedMessageExplicitUsageFails() { assertThat(compilation).hadErrorContaining(errMsg); } + /** Collection-of-entries encoding of a {@code Map}: generator recurses into each entry's KCO. */ + @Test + public void testKeyCacheObjectInCollectionOfEntries() { + Compilation compilation = compile("KeyCacheObjectEntryMsg.java", "TestKeyCacheObjectCollectionMessage.java"); + + assertThat(compilation).succeeded(); + + assertEquals(2, compilation.generatedSourceFiles().size()); + + assertThat(compilation) + .generatedSourceFile("org.apache.ignite.internal.KeyCacheObjectEntryMsgSerializer") + .hasSourceEquivalentTo(javaFile("KeyCacheObjectEntryMsgSerializer.java")); + + assertThat(compilation) + .generatedSourceFile("org.apache.ignite.internal.TestKeyCacheObjectCollectionMessageSerializer") + .hasSourceEquivalentTo(javaFile("TestKeyCacheObjectCollectionMessageSerializer.java")); + } + +/** {@code @Order Map}: generator walks keys/values via {@code keySet()/values()}. */ + @Test + public void testMapWithKeyCacheObjectAndMessageValue() { + Compilation compilation = compile("TestMapKeyCacheObjectMessage.java"); + + assertThat(compilation).succeeded(); + + assertThat(compilation) + .generatedSourceFile("org.apache.ignite.internal.TestMapKeyCacheObjectMessageSerializer") + .hasSourceEquivalentTo(javaFile("TestMapKeyCacheObjectMessageSerializer.java")); + } + /** * Negative test that verifies the compilation failed if the Compress annotation is used for unsupported types. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIoManagerRetryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIoManagerRetryTest.java index 0ab5cd5382219..39d54e07d8831 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIoManagerRetryTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIoManagerRetryTest.java @@ -27,6 +27,7 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.GridTopic; +import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.managers.communication.GridIoManager; import org.apache.ignite.internal.managers.deployment.GridDeploymentManager; import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager; @@ -128,6 +129,8 @@ private void doTest(Function action) throws Except cacheIoMgr.start(cctx); + ((IgniteKernal)cacheIoMgr.context().kernalContext().grid()).initMessageFactory(); + return cacheIoMgr; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetectionMessageMarshallingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetectionMessageMarshallingTest.java index a6d6375c1ed87..39ca06b06ec70 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetectionMessageMarshallingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetectionMessageMarshallingTest.java @@ -86,7 +86,7 @@ public void testMessageUnmarshallWithoutCacheContext() throws Exception { TxLocksResponse msg = new TxLocksResponse(); msg.addKey(cctx.txKey(key)); - msg.prepareMarshal(cctx.shared()); + msg.prepareDeployment(cctx.shared()); ((IgniteKernal)ignite).context().cache().context().gridIO().sendToCustomTopic( ((IgniteKernal)client).localNode(), TOPIC, msg, GridIoPolicy.PUBLIC_POOL); diff --git a/modules/core/src/test/java/org/apache/ignite/p2p/ClassLoadingProblemExceptionTest.java b/modules/core/src/test/java/org/apache/ignite/p2p/ClassLoadingProblemExceptionTest.java index 44a39859e05b7..3c4853ca04efe 100644 --- a/modules/core/src/test/java/org/apache/ignite/p2p/ClassLoadingProblemExceptionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/p2p/ClassLoadingProblemExceptionTest.java @@ -197,7 +197,7 @@ private class TestCommunicationSpi extends TcpCommunicationSpi { GridCacheQueryRequest qryReq = (GridCacheQueryRequest)m; if (qryReq.deployInfo() != null) { - qryReq.prepare( + qryReq.prepareDeployment( new GridDeploymentInfoBean( IgniteUuid.fromUuid(UUID.randomUUID()), qryReq.deployInfo().userVersion(), diff --git a/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsg.java b/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsg.java new file mode 100644 index 0000000000000..80d23d2e6ad09 --- /dev/null +++ b/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsg.java @@ -0,0 +1,35 @@ +/* + * 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.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.plugin.extensions.communication.Message; + +/** APT fixture: entry Message for {@link TestKeyCacheObjectCollectionMessage}. */ +public class KeyCacheObjectEntryMsg implements Message { + @Order(0) + KeyCacheObject key; + + @Order(1) + GridCacheVersion val; + + public short directType() { + return 0; + } +} diff --git a/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsgSerializer.java b/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsgSerializer.java new file mode 100644 index 0000000000000..59e90a33c9ade --- /dev/null +++ b/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsgSerializer.java @@ -0,0 +1,95 @@ +/* + * 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.IgniteCheckedException; +import org.apache.ignite.internal.KeyCacheObjectEntryMsg; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersionSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; + +/** + * This class is generated automatically. + * + * @see org.apache.ignite.internal.MessageProcessor + */ +public class KeyCacheObjectEntryMsgSerializer implements MessageSerializer { + /** */ + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); + + /** */ + @Override public boolean writeTo(KeyCacheObjectEntryMsg msg, MessageWriter writer) { + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(msg.directType())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 0: + if (!writer.writeKeyCacheObject(msg.key)) + return false; + + writer.incrementState(); + + case 1: + if (!writer.writeMessage(msg.val)) + return false; + + writer.incrementState(); + } + + return true; + } + + /** */ + @Override public boolean readFrom(KeyCacheObjectEntryMsg msg, MessageReader reader) { + switch (reader.state()) { + case 0: + msg.key = reader.readKeyCacheObject(); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 1: + msg.val = reader.readMessage(); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + } + + return true; + } + + /** */ + @Override public void prepareMarshalCacheObjects(KeyCacheObjectEntryMsg msg, CacheObjectValueContext ctx, GridCacheSharedContext sharedCtx) throws IgniteCheckedException { + if (msg.key != null) + msg.key.prepareMarshal(ctx); + + if (msg.val != null) + GRID_CACHE_VERSION_SER.prepareMarshalCacheObjects(msg.val, ctx, sharedCtx); + } +} \ No newline at end of file diff --git a/modules/core/src/test/resources/codegen/TestCollectionsMessageSerializer.java b/modules/core/src/test/resources/codegen/TestCollectionsMessageSerializer.java index 329f334337488..496d5c889d7e1 100644 --- a/modules/core/src/test/resources/codegen/TestCollectionsMessageSerializer.java +++ b/modules/core/src/test/resources/codegen/TestCollectionsMessageSerializer.java @@ -17,7 +17,12 @@ package org.apache.ignite.internal; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.TestCollectionsMessage; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersionSerializer; import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; import org.apache.ignite.plugin.extensions.communication.MessageCollectionType; import org.apache.ignite.plugin.extensions.communication.MessageItemType; @@ -32,55 +37,57 @@ */ public class TestCollectionsMessageSerializer implements MessageSerializer { /** */ - private final static MessageCollectionType affTopVersionListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), false); + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); /** */ - private final static MessageCollectionType bitSetListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BIT_SET), false); + private static final MessageCollectionType affTopVersionListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), false); /** */ - private final static MessageCollectionType bitSetSetCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BIT_SET), true); + private static final MessageCollectionType bitSetListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BIT_SET), false); /** */ - private final static MessageCollectionType booleanArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), false); + private static final MessageCollectionType bitSetSetCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BIT_SET), true); /** */ - private final static MessageCollectionType boxedBooleanListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BOOLEAN), false); + private static final MessageCollectionType booleanArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), false); /** */ - private final static MessageCollectionType boxedByteListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BYTE), false); + private static final MessageCollectionType boxedBooleanListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BOOLEAN), false); /** */ - private final static MessageCollectionType boxedCharListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.CHAR), false); + private static final MessageCollectionType boxedByteListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BYTE), false); /** */ - private final static MessageCollectionType boxedDoubleListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE), false); + private static final MessageCollectionType boxedCharListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.CHAR), false); /** */ - private final static MessageCollectionType boxedFloatListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.FLOAT), false); + private static final MessageCollectionType boxedDoubleListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE), false); /** */ - private final static MessageCollectionType boxedIntListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT), false); + private static final MessageCollectionType boxedFloatListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.FLOAT), false); /** */ - private final static MessageCollectionType boxedIntegerSetCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT), true); + private static final MessageCollectionType boxedIntListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT), false); /** */ - private final static MessageCollectionType boxedLongListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.LONG), false); + private static final MessageCollectionType boxedIntegerSetCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT), true); /** */ - private final static MessageCollectionType boxedShortListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.SHORT), false); + private static final MessageCollectionType boxedLongListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.LONG), false); /** */ - private final static MessageCollectionType byteArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BYTE_ARR), false); + private static final MessageCollectionType boxedShortListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.SHORT), false); /** */ - private final static MessageCollectionType charArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.CHAR_ARR), false); + private static final MessageCollectionType byteArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BYTE_ARR), false); /** */ - private final static MessageCollectionType doubleArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), false); + private static final MessageCollectionType charArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.CHAR_ARR), false); /** */ - private final static MessageCollectionType floatArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.FLOAT_ARR), false); + private static final MessageCollectionType doubleArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), false); /** */ - private final static MessageCollectionType gridLongListListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), false); + private static final MessageCollectionType floatArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.FLOAT_ARR), false); /** */ - private final static MessageCollectionType igniteUuidListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.IGNITE_UUID), false); + private static final MessageCollectionType gridLongListListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), false); /** */ - private final static MessageCollectionType intArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT_ARR), false); + private static final MessageCollectionType igniteUuidListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.IGNITE_UUID), false); /** */ - private final static MessageCollectionType longArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.LONG_ARR), false); + private static final MessageCollectionType intArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT_ARR), false); /** */ - private final static MessageCollectionType messageListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.MSG), false); + private static final MessageCollectionType longArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.LONG_ARR), false); /** */ - private final static MessageCollectionType shortArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.SHORT_ARR), false); + private static final MessageCollectionType messageListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.MSG), false); /** */ - private final static MessageCollectionType stringListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.STRING), false); + private static final MessageCollectionType shortArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.SHORT_ARR), false); /** */ - private final static MessageCollectionType uuidListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.UUID), false); + private static final MessageCollectionType stringListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.STRING), false); + /** */ + private static final MessageCollectionType uuidListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.UUID), false); /** */ @Override public boolean writeTo(TestCollectionsMessage msg, MessageWriter writer) { @@ -452,4 +459,14 @@ public class TestCollectionsMessageSerializer implements MessageSerializer} field. */ +public class TestKeyCacheObjectCollectionMessage implements Message { + @Order(0) + Collection entries; + + @Order(1) + KeyCacheObjectEntryMsg[] entriesArr; + + public short directType() { + return 1; + } +} diff --git a/modules/core/src/test/resources/codegen/TestKeyCacheObjectCollectionMessageSerializer.java b/modules/core/src/test/resources/codegen/TestKeyCacheObjectCollectionMessageSerializer.java new file mode 100644 index 0000000000000..70510b79eee0c --- /dev/null +++ b/modules/core/src/test/resources/codegen/TestKeyCacheObjectCollectionMessageSerializer.java @@ -0,0 +1,112 @@ +/* + * 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.IgniteCheckedException; +import org.apache.ignite.internal.KeyCacheObjectEntryMsg; +import org.apache.ignite.internal.KeyCacheObjectEntryMsgSerializer; +import org.apache.ignite.internal.TestKeyCacheObjectCollectionMessage; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.plugin.extensions.communication.MessageArrayType; +import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; +import org.apache.ignite.plugin.extensions.communication.MessageCollectionType; +import org.apache.ignite.plugin.extensions.communication.MessageItemType; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; + +/** + * This class is generated automatically. + * + * @see org.apache.ignite.internal.MessageProcessor + */ +public class TestKeyCacheObjectCollectionMessageSerializer implements MessageSerializer { + /** */ + private final static KeyCacheObjectEntryMsgSerializer KEY_CACHE_OBJECT_ENTRY_MSG_SER = new KeyCacheObjectEntryMsgSerializer(); + /** */ + private static final MessageArrayType entriesArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.MSG), KeyCacheObjectEntryMsg.class); + /** */ + private static final MessageCollectionType entriesCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.MSG), false); + + /** */ + @Override public boolean writeTo(TestKeyCacheObjectCollectionMessage msg, MessageWriter writer) { + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(msg.directType())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 0: + if (!writer.writeCollection(msg.entries, entriesCollDesc)) + return false; + + writer.incrementState(); + + case 1: + if (!writer.writeObjectArray(msg.entriesArr, entriesArrCollDesc)) + return false; + + writer.incrementState(); + } + + return true; + } + + /** */ + @Override public boolean readFrom(TestKeyCacheObjectCollectionMessage msg, MessageReader reader) { + switch (reader.state()) { + case 0: + msg.entries = reader.readCollection(entriesCollDesc); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 1: + msg.entriesArr = reader.readObjectArray(entriesArrCollDesc); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + } + + return true; + } + + /** */ + @Override public void prepareMarshalCacheObjects(TestKeyCacheObjectCollectionMessage msg, CacheObjectValueContext ctx, GridCacheSharedContext sharedCtx) throws IgniteCheckedException { + if (msg.entries != null) { + for (KeyCacheObjectEntryMsg e : msg.entries) { + if (e != null) + KEY_CACHE_OBJECT_ENTRY_MSG_SER.prepareMarshalCacheObjects(e, ctx, sharedCtx); + } + } + + if (msg.entriesArr != null) { + for (KeyCacheObjectEntryMsg e : msg.entriesArr) { + if (e != null) + KEY_CACHE_OBJECT_ENTRY_MSG_SER.prepareMarshalCacheObjects(e, ctx, sharedCtx); + } + } + } +} diff --git a/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessage.java b/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessage.java new file mode 100644 index 0000000000000..1956319cef672 --- /dev/null +++ b/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessage.java @@ -0,0 +1,33 @@ +/* + * 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.util.Map; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.plugin.extensions.communication.Message; + +/** APT fixture: {@code @Order Map} is safe — deferred {@code HashMap} assembly. */ +public class TestMapKeyCacheObjectMessage implements Message { + @Order(0) + Map entries; + + public short directType() { + return 0; + } +} diff --git a/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessageSerializer.java b/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessageSerializer.java new file mode 100644 index 0000000000000..c7217c0dba9e3 --- /dev/null +++ b/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessageSerializer.java @@ -0,0 +1,94 @@ +/* + * 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.IgniteCheckedException; +import org.apache.ignite.internal.TestMapKeyCacheObjectMessage; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersionSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; +import org.apache.ignite.plugin.extensions.communication.MessageItemType; +import org.apache.ignite.plugin.extensions.communication.MessageMapType; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; + +/** + * This class is generated automatically. + * + * @see org.apache.ignite.internal.MessageProcessor + */ +public class TestMapKeyCacheObjectMessageSerializer implements MessageSerializer { + /** */ + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); + /** */ + private static final MessageMapType entriesCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.KEY_CACHE_OBJECT), new MessageItemType(MessageCollectionItemType.MSG), false); + + /** */ + @Override public boolean writeTo(TestMapKeyCacheObjectMessage msg, MessageWriter writer) { + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(msg.directType())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 0: + if (!writer.writeMap(msg.entries, entriesCollDesc)) + return false; + + writer.incrementState(); + } + + return true; + } + + /** */ + @Override public boolean readFrom(TestMapKeyCacheObjectMessage msg, MessageReader reader) { + switch (reader.state()) { + case 0: + msg.entries = reader.readMap(entriesCollDesc); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + } + + return true; + } + + /** */ + @Override public void prepareMarshalCacheObjects(TestMapKeyCacheObjectMessage msg, CacheObjectValueContext ctx, GridCacheSharedContext sharedCtx) throws IgniteCheckedException { + if (msg.entries != null) { + for (KeyCacheObject k : msg.entries.keySet()) { + if (k != null) + k.prepareMarshal(ctx); + } + + for (GridCacheVersion v : msg.entries.values()) { + if (v != null) + GRID_CACHE_VERSION_SER.prepareMarshalCacheObjects(v, ctx, sharedCtx); + } + } + } +} \ No newline at end of file diff --git a/modules/core/src/test/resources/codegen/TestMapMessageSerializer.java b/modules/core/src/test/resources/codegen/TestMapMessageSerializer.java index b2e66053653df..d210abbc82ba8 100644 --- a/modules/core/src/test/resources/codegen/TestMapMessageSerializer.java +++ b/modules/core/src/test/resources/codegen/TestMapMessageSerializer.java @@ -17,7 +17,12 @@ package org.apache.ignite.internal; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.TestMapMessage; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersionSerializer; import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; import org.apache.ignite.plugin.extensions.communication.MessageCollectionType; import org.apache.ignite.plugin.extensions.communication.MessageItemType; @@ -33,55 +38,57 @@ */ public class TestMapMessageSerializer implements MessageSerializer { /** */ - private final static MessageMapType affTopVersionIgniteUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), new MessageItemType(MessageCollectionItemType.IGNITE_UUID), false); + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); /** */ - private final static MessageMapType bitSetUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BIT_SET), new MessageItemType(MessageCollectionItemType.UUID), false); + private static final MessageMapType affTopVersionIgniteUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), new MessageItemType(MessageCollectionItemType.IGNITE_UUID), false); /** */ - private final static MessageMapType booleanArrayBoxedLongMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), new MessageItemType(MessageCollectionItemType.LONG), false); + private static final MessageMapType bitSetUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BIT_SET), new MessageItemType(MessageCollectionItemType.UUID), false); /** */ - private final static MessageMapType boxedBooleanAffTopVersionMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BOOLEAN), new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), false); + private static final MessageMapType booleanArrayBoxedLongMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), new MessageItemType(MessageCollectionItemType.LONG), false); /** */ - private final static MessageMapType boxedByteBoxedBooleanMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BYTE), new MessageItemType(MessageCollectionItemType.BOOLEAN), false); + private static final MessageMapType boxedBooleanAffTopVersionMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BOOLEAN), new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), false); /** */ - private final static MessageMapType boxedCharBoxedLongMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.CHAR), new MessageItemType(MessageCollectionItemType.LONG), false); + private static final MessageMapType boxedByteBoxedBooleanMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BYTE), new MessageItemType(MessageCollectionItemType.BOOLEAN), false); /** */ - private final static MessageMapType boxedDoubleBoxedFloatMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.DOUBLE), new MessageItemType(MessageCollectionItemType.FLOAT), false); + private static final MessageMapType boxedCharBoxedLongMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.CHAR), new MessageItemType(MessageCollectionItemType.LONG), false); /** */ - private final static MessageMapType boxedFloatBoxedCharMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.FLOAT), new MessageItemType(MessageCollectionItemType.CHAR), false); + private static final MessageMapType boxedDoubleBoxedFloatMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.DOUBLE), new MessageItemType(MessageCollectionItemType.FLOAT), false); /** */ - private final static MessageMapType boxedIntBoxedShortMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT), new MessageItemType(MessageCollectionItemType.SHORT), false); + private static final MessageMapType boxedFloatBoxedCharMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.FLOAT), new MessageItemType(MessageCollectionItemType.CHAR), false); /** */ - private final static MessageMapType boxedLongBoxedIntMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.LONG), new MessageItemType(MessageCollectionItemType.INT), false); + private static final MessageMapType boxedIntBoxedShortMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT), new MessageItemType(MessageCollectionItemType.SHORT), false); /** */ - private final static MessageMapType boxedShortBoxedByteMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.SHORT), new MessageItemType(MessageCollectionItemType.BYTE), false); + private static final MessageMapType boxedLongBoxedIntMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.LONG), new MessageItemType(MessageCollectionItemType.INT), false); /** */ - private final static MessageMapType byteArrayBooleanArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BYTE_ARR), new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), false); + private static final MessageMapType boxedShortBoxedByteMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.SHORT), new MessageItemType(MessageCollectionItemType.BYTE), false); /** */ - private final static MessageMapType charArrayLongArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.CHAR_ARR), new MessageItemType(MessageCollectionItemType.LONG_ARR), false); + private static final MessageMapType byteArrayBooleanArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BYTE_ARR), new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), false); /** */ - private final static MessageMapType doubleArrayFloatArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), new MessageItemType(MessageCollectionItemType.FLOAT_ARR), false); + private static final MessageMapType charArrayLongArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.CHAR_ARR), new MessageItemType(MessageCollectionItemType.LONG_ARR), false); /** */ - private final static MessageMapType floatArrayCharArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.FLOAT_ARR), new MessageItemType(MessageCollectionItemType.CHAR_ARR), false); + private static final MessageMapType doubleArrayFloatArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), new MessageItemType(MessageCollectionItemType.FLOAT_ARR), false); /** */ - private final static MessageMapType gridLongListIntegerMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), new MessageItemType(MessageCollectionItemType.INT), false); + private static final MessageMapType floatArrayCharArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.FLOAT_ARR), new MessageItemType(MessageCollectionItemType.CHAR_ARR), false); /** */ - private final static MessageMapType gridlistDoubleMapUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), new MessageMapType(new MessageItemType(MessageCollectionItemType.UUID), new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE), false), false), false); + private static final MessageMapType gridLongListIntegerMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), new MessageItemType(MessageCollectionItemType.INT), false); /** */ - private final static MessageMapType igniteUuidBitSetMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.IGNITE_UUID), new MessageItemType(MessageCollectionItemType.BIT_SET), false); + private static final MessageMapType gridlistDoubleMapUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), new MessageMapType(new MessageItemType(MessageCollectionItemType.UUID), new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE), false), false), false); /** */ - private final static MessageMapType intArrayShortArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT_ARR), new MessageItemType(MessageCollectionItemType.SHORT_ARR), false); + private static final MessageMapType igniteUuidBitSetMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.IGNITE_UUID), new MessageItemType(MessageCollectionItemType.BIT_SET), false); /** */ - private final static MessageMapType integerGridLongListMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT), new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), false); + private static final MessageMapType intArrayShortArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT_ARR), new MessageItemType(MessageCollectionItemType.SHORT_ARR), false); /** */ - private final static MessageMapType longArrayIntArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.LONG_ARR), new MessageItemType(MessageCollectionItemType.INT_ARR), false); + private static final MessageMapType integerGridLongListMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT), new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), false); /** */ - private final static MessageMapType messageBoxedDoubleMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.MSG), new MessageItemType(MessageCollectionItemType.DOUBLE), false); + private static final MessageMapType longArrayIntArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.LONG_ARR), new MessageItemType(MessageCollectionItemType.INT_ARR), false); /** */ - private final static MessageMapType shortArrayByteArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.SHORT_ARR), new MessageItemType(MessageCollectionItemType.BYTE_ARR), false); + private static final MessageMapType messageBoxedDoubleMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.MSG), new MessageItemType(MessageCollectionItemType.DOUBLE), false); /** */ - private final static MessageMapType stringDoubleArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.STRING), new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), false); + private static final MessageMapType shortArrayByteArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.SHORT_ARR), new MessageItemType(MessageCollectionItemType.BYTE_ARR), false); /** */ - private final static MessageMapType uuidStringMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.UUID), new MessageItemType(MessageCollectionItemType.STRING), false); + private static final MessageMapType stringDoubleArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.STRING), new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), false); + /** */ + private static final MessageMapType uuidStringMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.UUID), new MessageItemType(MessageCollectionItemType.STRING), false); /** */ @Override public boolean writeTo(TestMapMessage msg, MessageWriter writer) { @@ -453,4 +460,14 @@ public class TestMapMessageSerializer implements MessageSerializer { /** */ - private final static MessageArrayType intMatrixCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.INT_ARR), int[].class); + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); /** */ - private final static MessageArrayType strArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.STRING), String.class); + private static final MessageArrayType intMatrixCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.INT_ARR), int[].class); /** */ - private final static MessageArrayType verArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.MSG), GridCacheVersion.class); + private static final MessageArrayType strArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.STRING), String.class); + /** */ + private static final MessageArrayType verArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.MSG), GridCacheVersion.class); /** */ @Override public boolean writeTo(TestMessage msg, MessageWriter writer) { @@ -269,4 +275,23 @@ public class TestMessageSerializer implements MessageSerializer { return true; } + + /** */ + @Override public void prepareMarshalCacheObjects(TestMessage msg, CacheObjectValueContext ctx, GridCacheSharedContext sharedCtx) throws IgniteCheckedException { + if (msg.ver != null) + GRID_CACHE_VERSION_SER.prepareMarshalCacheObjects(msg.ver, ctx, sharedCtx); + + if (msg.verArr != null) { + for (GridCacheVersion e : msg.verArr) { + if (e != null) + GRID_CACHE_VERSION_SER.prepareMarshalCacheObjects(e, ctx, sharedCtx); + } + } + + if (msg.keyCacheObject != null) + msg.keyCacheObject.prepareMarshal(ctx); + + if (msg.cacheObject != null) + msg.cacheObject.prepareMarshal(ctx); + } } \ No newline at end of file