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..8f5d44a466336 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 @@ -97,12 +97,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..9c875118caad8 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 @@ -52,6 +52,7 @@ 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 +75,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 + @@ -114,6 +115,9 @@ public class MessageSerializerGenerator { /** The marshallable message type. */ private final TypeMirror marshallableMsgType; + /** */ + private final List prepareCacheObjects = new ArrayList<>(); + /** */ private int indent; @@ -189,9 +193,14 @@ private String generateSerializerCode(String serClsName) throws IOException { writer.write(TAB + "}" + NL); - writer.write("}"); + if (!prepareCacheObjects.isEmpty()) { + writer.write(NL); - writer.write(NL); + for (String p: prepareCacheObjects) + writer.write(p + NL); + } + + writer.write("}"); return writer.toString(); } @@ -242,6 +251,496 @@ private void generateMethods(List fields) throws Exception { finish(write, false, false); finish(read, true, marshallableMessage()); + + generateCacheObjectMarshallMethods(fields); + } + + /** */ + private void generateCacheObjectMarshallMethods(List orderedFields) throws Exception { + List traversable = new ArrayList<>(); + + for (VariableElement field: orderedFields) { + if (classify(field.asType()) != FieldKind.SKIP) + traversable.add(field); + } + + if (traversable.isEmpty()) + return; + + 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"); + + startCacheObjectMethod(prepareCacheObjects); + + indent++; + + if (isCacheIdAwareMessage(type)) + prepareCacheObjects.add( + identedLine("GridCacheContext ctx = nested == null ? sctx.cacheContext(msg.cacheId()) : nested;")); + else + prepareCacheObjects.add(identedLine("GridCacheContext ctx = nested;")); + + prepareCacheObjects.add(EMPTY); + + boolean first = true; + + for (VariableElement field: traversable) { + if (!first) + prepareCacheObjects.add(EMPTY); + + emitCacheObjectCall(prepareCacheObjects, field); + + first = false; + } + + indent--; + + prepareCacheObjects.add(identedLine("}")); + } + + /** Traversal kinds for {@link #generateCacheObjectMarshallMethods}. */ + private enum FieldKind { + /** {@code CacheObject} / {@code KeyCacheObject} scalar. */ + CO, + /** {@code Collection} / {@code Collection}. */ + CO_COLL, + /** {@code CacheObject[]} / {@code KeyCacheObject[]}. */ + CO_ARR, + /** {@code CacheEntryPredicate} scalar. */ + CEP, + /** {@code Collection}. */ + CEP_COLL, + /** {@code CacheEntryPredicate[]}. */ + CEP_ARR, + /** Nested concrete {@code Message}. */ + MSG, + /** {@code Collection} with concrete element type. */ + MSG_COLL, + /** {@code Message[]} with concrete component type. */ + MSG_ARR, + /** {@code Map} with at least one CacheObject/Message side. */ + MAP, + /** Skipped — abstract Message, cross-cache nested Message, Map with no traversable side, unsupported. */ + SKIP + } + + /** */ + private FieldKind classify(TypeMirror t) { + if (t.getKind() == TypeKind.ARRAY) { + TypeMirror comp = ((ArrayType)t).getComponentType(); + + if (comp.getKind() != TypeKind.DECLARED) + return FieldKind.SKIP; + + if (isCacheObjectType(comp)) + return FieldKind.CO_ARR; + + if (isCacheEntryPredicate(comp)) + return FieldKind.CEP_ARR; + + return isRecursableMessage(comp) ? FieldKind.MSG_ARR : FieldKind.SKIP; + } + + if (t.getKind() != TypeKind.DECLARED) + return FieldKind.SKIP; + + if (isCacheObjectType(t)) + return FieldKind.CO; + + if (isCacheEntryPredicate(t)) + return FieldKind.CEP; + + if (assignableFrom(erasedType(t), type(Map.class.getName()))) { + List args = ((DeclaredType)t).getTypeArguments(); + + if (args.size() != 2) + return FieldKind.SKIP; + + FieldKind kSide = classifyMapSide(args.get(0)); + FieldKind vSide = classifyMapSide(args.get(1)); + + if (kSide == FieldKind.SKIP && vSide == FieldKind.SKIP) + return FieldKind.SKIP; + + return FieldKind.MAP; + } + + if (assignableFrom(erasedType(t), type(Collection.class.getName()))) { + List args = ((DeclaredType)t).getTypeArguments(); + + if (args.size() != 1) + return FieldKind.SKIP; + + TypeMirror arg = args.get(0); + + if (arg.getKind() != TypeKind.DECLARED) + return FieldKind.SKIP; + + if (isCacheObjectType(arg)) + return FieldKind.CO_COLL; + + if (isCacheEntryPredicate(arg)) + return FieldKind.CEP_COLL; + + return isRecursableMessage(arg) ? FieldKind.MSG_COLL : FieldKind.SKIP; + } + + return isRecursableMessage(t) ? FieldKind.MSG : FieldKind.SKIP; + } + + /** Classifies one side (key or value) of a {@code Map} field: {@link FieldKind#CO}, {@link FieldKind#MSG}, or + * {@link FieldKind#SKIP}. */ + private FieldKind classifyMapSide(TypeMirror t) { + if (t.getKind() != TypeKind.DECLARED) + return FieldKind.SKIP; + + if (isCacheObjectType(t)) + return FieldKind.CO; + + if (isCacheEntryPredicate(t)) + return FieldKind.CEP; + + return isRecursableMessage(t) ? FieldKind.MSG : FieldKind.SKIP; + } + + /** */ + private boolean isCacheObjectType(TypeMirror type) { + return assignableFrom(type, type("org.apache.ignite.internal.processors.cache.CacheObject")); + } + + /** */ + private boolean isCacheEntryPredicate(TypeMirror type) { + return assignableFrom(type, type("org.apache.ignite.internal.processors.cache.CacheEntryPredicate")); + } + + /** True if {@code t} is a concrete non-abstract {@code Message} safe to recurse into (no self-ref). */ + private boolean isRecursableMessage(TypeMirror t) { + TypeMirror msgIface = type(MESSAGE_INTERFACE); + + if (msgIface == null || !assignableFrom(t, msgIface)) + return false; + + Element el = env.getTypeUtils().asElement(t); + + if (!(el instanceof TypeElement)) + return false; + + TypeElement te = (TypeElement)el; + + return !te.equals(type); + } + + /** 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 void startCacheObjectMethod(List code) { + indent = 1; + + code.add(identedLine(METHOD_JAVADOC)); + + code.add(identedLine( + "@Override public void prepareMarshalCacheObjects(" + simpleNameWithGeneric(type) + + " msg, GridCacheSharedContext sctx, GridCacheContext nested) throws IgniteCheckedException {")); + } + + /** */ + private void emitCacheObjectCall(List code, VariableElement field) { + String accessor = fieldAccessor(field); + TypeMirror t = field.asType(); + FieldKind kind = classify(t); + + switch (kind) { + case CO: + emitCoDirect(code, accessor); + break; + + case CO_COLL: + case CO_ARR: + emitCoIterable(code, accessor, t, kind == FieldKind.CO_ARR); + break; + + case CEP: + emitCepDirect(code, accessor); + break; + + case CEP_COLL: + case CEP_ARR: + emitCepIterable(code, accessor); + break; + + case MSG: + emitMsgDirect(code, accessor); + break; + + case MSG_COLL: + emitMsgIterable(code, accessor, (DeclaredType)((DeclaredType)t).getTypeArguments().get(0)); + break; + + case MSG_ARR: + emitMsgIterable(code, accessor, (DeclaredType)((ArrayType)t).getComponentType()); + break; + + case MAP: + emitMapTraversal(code, accessor, (DeclaredType)t); + break; + + default: + throw new IllegalStateException("Unexpected kind: " + kind); + } + } + + /** */ + private void emitMapTraversal(List code, String accessor, DeclaredType mapType) { + List args = mapType.getTypeArguments(); + + TypeMirror keyT = args.get(0); + TypeMirror valT = args.get(1); + + FieldKind kSide = classifyMapSide(keyT); + FieldKind vSide = classifyMapSide(valT); + + code.add(identedLine("if (%s != null) {", accessor)); + + indent++; + + if (kSide != FieldKind.SKIP) + emitMapSideIteration(code, accessor, keyT, kSide, true); + + if (kSide != FieldKind.SKIP && vSide != FieldKind.SKIP) + code.add(EMPTY); + + if (vSide != FieldKind.SKIP) + emitMapSideIteration(code, accessor, valT, vSide, false); + + indent--; + + code.add(identedLine("}")); + } + + /** */ + private void emitMapSideIteration( + List code, + String accessor, + TypeMirror sideType, + FieldKind sideKind, + boolean isKey + ) { + String side = accessor + (isKey ? ".keySet()" : ".values()"); + + String var = isKey ? "k" : "v"; + + if (sideKind == FieldKind.CO) { + String elementType = "org.apache.ignite.internal.processors.cache.KeyCacheObject"; + + if (!assignableFrom(sideType, type(elementType))) + elementType = "org.apache.ignite.internal.processors.cache.CacheObject"; + + imports.add(elementType); + + String simple = elementType.substring(elementType.lastIndexOf('.') + 1); + + code.add(identedLine("for (%s %s : %s) {", simple, var, side)); + + indent++; + + code.add(identedLine("if (%s != null)", var)); + + indent++; + + code.add(identedLine("%s.prepareMarshal(ctx.cacheObjectContext());", var)); + + indent--; + indent--; + + code.add(identedLine("}")); + } + else { + assert sideKind == FieldKind.MSG : sideKind; + + DeclaredType msgType = (DeclaredType)sideType; + String elemSimple = msgType.asElement().getSimpleName().toString(); + + imports.add(((TypeElement)msgType.asElement()).getQualifiedName().toString()); + + code.add(identedLine("for (%s %s : %s) {", elemSimple, var, side)); + + indent++; + + code.add(identedLine("if (%s != null)", var)); + + indent++; + + code.add(identedLine( + "sctx.gridIO().messageFactory().serializer(%s.directType()).prepareMarshalCacheObjects(%s, sctx, ctx);", var, var)); + + indent--; + indent--; + + code.add(identedLine("}")); + } + } + + /** */ + private void emitCoDirect(List code, String accessor) { + code.add(identedLine("if (%s != null)", accessor)); + + indent++; + + code.add(identedLine("%s.prepareMarshal(ctx.cacheObjectContext());", accessor)); + + indent--; + } + + /** */ + private void emitCoIterable(List code, String accessor, TypeMirror t, boolean isArr) { + String elementType = "org.apache.ignite.internal.processors.cache.KeyCacheObject"; + + TypeMirror elem = isArr ? ((ArrayType)t).getComponentType() : ((DeclaredType)t).getTypeArguments().get(0); + + if (!assignableFrom(elem, type(elementType))) + elementType = "org.apache.ignite.internal.processors.cache.CacheObject"; + + imports.add(elementType); + + String simple = elementType.substring(elementType.lastIndexOf('.') + 1); + + code.add(identedLine("if (%s != null) {", accessor)); + + indent++; + + code.add(identedLine("for (%s obj : %s) {", simple, accessor)); + + indent++; + + code.add(identedLine("if (obj != null)")); + + indent++; + + code.add(identedLine("obj.prepareMarshal(ctx.cacheObjectContext());")); + + indent--; + + indent--; + + code.add(identedLine("}")); + + indent--; + + code.add(identedLine("}")); + } + + /** */ + private void emitCepDirect(List code, String accessor) { + code.add(identedLine("if (%s != null)", accessor)); + + indent++; + + code.add(identedLine("%s.prepareMarshal(ctx);", accessor)); + + indent--; + } + + /** */ + private void emitCepIterable(List code, String accessor) { + String elementType = "org.apache.ignite.internal.processors.cache.CacheEntryPredicate"; + + imports.add(elementType); + + String simple = elementType.substring(elementType.lastIndexOf('.') + 1); + + code.add(identedLine("if (%s != null) {", accessor)); + + indent++; + + code.add(identedLine("for (%s obj : %s) {", simple, accessor)); + + indent++; + + code.add(identedLine("if (obj != null)")); + + indent++; + + code.add(identedLine("obj.prepareMarshal(ctx);")); + + indent--; + + indent--; + + code.add(identedLine("}")); + + indent--; + + code.add(identedLine("}")); + } + + /** */ + private void emitMsgDirect(List code, String accessor) { + code.add(identedLine("if (%s != null)", accessor)); + + indent++; + + code.add(identedLine( + "sctx.gridIO().messageFactory().serializer(%s.directType()).prepareMarshalCacheObjects(%s, sctx, ctx);", accessor, accessor)); + + indent--; + } + + /** */ + private void emitMsgIterable(List code, String accessor, DeclaredType elemType) { + String elemSimple = elemType.asElement().getSimpleName().toString(); + + imports.add(((TypeElement)elemType.asElement()).getQualifiedName().toString()); + + code.add(identedLine("if (%s != null) {", accessor)); + + indent++; + + code.add(identedLine("for (%s e : %s) {", elemSimple, accessor)); + + indent++; + + code.add(identedLine("if (e != null)")); + + indent++; + + code.add(identedLine("sctx.gridIO().messageFactory().serializer(e.directType()).prepareMarshalCacheObjects(e, sctx, ctx);")); + + indent--; + indent--; + + code.add(identedLine("}")); + + indent--; + + code.add(identedLine("}")); + } + + /** Converts {@code CacheInvokeDirectResult} to {@code CACHE_INVOKE_DIRECT_RESULT}. */ + private static String camelToConstant(String simple) { + StringBuilder sb = new StringBuilder(simple.length() + 8); + + for (int i = 0; i < simple.length(); i++) { + char c = simple.charAt(i); + + if (i > 0 && Character.isUpperCase(c) && !Character.isUpperCase(simple.charAt(i - 1))) + sb.append('_'); + + sb.append(Character.toUpperCase(c)); + } + + return sb.toString(); + } + + /** */ + private String fieldAccessor(VariableElement field) { + String name = field.getSimpleName().toString(); + + return "msg." + name; } /** @@ -264,7 +763,7 @@ private void start(Collection code, boolean write) { code.add(identedLine(METHOD_JAVADOC)); - code.add(identedLine("@Override public boolean %s(" + type.getSimpleName() + " msg, %s) {", + code.add(identedLine("@Override public boolean %s(" + simpleNameWithGeneric(type) + " msg, %s) {", write ? "writeTo" : "readFrom", write ? "MessageWriter writer" : "MessageReader reader")); @@ -1048,7 +1547,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 +1643,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/processors/cache/CacheEntryPredicateAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java index 0c30dc615aa66..69da0dbec23f3 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 @@ -127,8 +127,6 @@ public CacheEntryPredicateType type() { /** {@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/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 5c639d08b2596..4df2a0a533d74 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 @@ -91,6 +91,7 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiInClosure; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; import org.apache.ignite.thread.IgniteThread; import org.jetbrains.annotations.Nullable; @@ -1149,6 +1150,11 @@ private boolean onSend(GridCacheMessage msg, @Nullable UUID destNodeId) throws I if (destNodeId == null || !cctx.localNodeId().equals(destNodeId)) { msg.prepareMarshal(cctx); + + MessageSerializer ser = cctx.gridIO().messageFactory().serializer(msg.directType()); + + if (ser != null) + ser.prepareMarshalCacheObjects(msg, cctx, null); 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..1d1e564612ea3 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 @@ -291,15 +291,13 @@ 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 prepareInfo(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); @@ -335,7 +333,7 @@ protected final void unmarshalInfo(GridCacheEntryInfo info, GridCacheContext ctx * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void marshalInfos( + protected final void prepareInfos( Iterable infos, GridCacheSharedContext ctx, CacheObjectContext cacheObjCtx @@ -344,7 +342,7 @@ protected final void marshalInfos( if (infos != null) for (GridCacheEntryInfo e : infos) - marshalInfo(e, ctx, cacheObjCtx); + prepareInfo(e, ctx, cacheObjCtx); } /** @@ -368,17 +366,14 @@ protected final void unmarshalInfos(Iterable infos * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void marshalTx(Iterable txEntries, GridCacheSharedContext ctx) + protected final void prepareTx(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) { @@ -404,13 +399,6 @@ else if (p2pEnabled && e.entryProcessors() != null) { } } - /** - * @return {@code True} if entries expire policy should be marshalled. - */ - protected boolean transferExpiryPolicy() { - return false; - } - /** * @param txEntries Entries to unmarshal. * @param ctx Context. @@ -492,7 +480,7 @@ protected final void unmarshalTx(Iterable txEntries, * @return Marshalled collection. * @throws IgniteCheckedException If failed. */ - @Nullable protected List marshalCollection(@Nullable Collection col, + @Nullable protected List marshalAndPrepareCollection(@Nullable Collection col, GridCacheContext ctx) throws IgniteCheckedException { assert ctx != null; @@ -517,7 +505,7 @@ protected final void unmarshalTx(Iterable txEntries, * @throws IgniteCheckedException If failed. */ @SuppressWarnings("ForLoopReplaceableByForEach") - public final void prepareMarshalCacheObjects(@Nullable List col, + public final void prepareCacheObjects(@Nullable List col, GridCacheContext ctx) throws IgniteCheckedException { if (col == null) return; @@ -525,7 +513,7 @@ public final void prepareMarshalCacheObjects(@Nullable List col, + protected final void prepareCacheObjects(@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()); } 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..3750312df3113 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 @@ -161,9 +161,9 @@ public List nearVersions() { GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjects(keys, cctx); - prepareMarshalCacheObjects(nearKeys, cctx); + prepareCacheObjects(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..edba35b3ff27e 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 @@ -353,7 +353,7 @@ public long timeout() { GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjects(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..4bcb22b0b17b8 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 @@ -164,7 +164,7 @@ protected int valuesSize() { @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { super.prepareMarshal(ctx); - prepareMarshalCacheObjects(vals, ctx.cacheContext(cacheId)); + prepareCacheObjects(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..b26dc8bce8bf2 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 @@ -26,7 +26,6 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; 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; @@ -376,18 +375,12 @@ public void applicationAttributes(Map appAttrs) { super.prepareMarshal(ctx); if (writes != null) - marshalTx(writes, ctx); + prepareTx(writes, ctx); if (reads != null) - marshalTx(reads, ctx); + prepareTx(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(); } 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..fb4feade50f68 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 @@ -98,7 +98,7 @@ public void addKey(KeyCacheObject key) { @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { super.prepareMarshal(ctx); - prepareMarshalCacheObjects(keys, ctx.cacheContext(cacheId)); + prepareCacheObjects(keys, ctx.cacheContext(cacheId)); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java index e73f606c827eb..49e155a8dfab7 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 @@ -130,7 +130,7 @@ public Collection preloadEntries() { GridCacheContext cctx = ctx.cacheContext(cacheId); if (preloadEntries != null) - marshalInfos(preloadEntries, cctx.shared(), cctx.cacheObjectContext()); + prepareInfos(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..3d43238e6310f 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 @@ -331,15 +331,13 @@ public boolean skipCompletedVersion() { for (IgniteTxKey key: ownedKeys) { GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - key.prepareMarshal(cctx); - if (addDepInfo) prepareObject(key, cctx); } } if (nearWrites != null) - marshalTx(nearWrites, ctx); + prepareTx(nearWrites, ctx); } /** {@inheritDoc} */ 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..d2d97808d3986 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 @@ -74,7 +74,7 @@ public void addNearKey(KeyCacheObject key) @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { super.prepareMarshal(ctx); - prepareMarshalCacheObjects(nearKeys, ctx.cacheContext(cacheId)); + prepareCacheObjects(nearKeys, ctx.cacheContext(cacheId)); } /** {@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..6fcd2e5ab3bf3 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 @@ -467,15 +467,15 @@ else if (conflictVers != null) GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjects(keys, cctx); - prepareMarshalCacheObjects(vals, cctx); + prepareCacheObjects(vals, cctx); - prepareMarshalCacheObjects(nearKeys, cctx); + prepareCacheObjects(nearKeys, cctx); - prepareMarshalCacheObjects(nearVals, cctx); + prepareCacheObjects(nearVals, cctx); - prepareMarshalCacheObjects(prevVals, cctx); + prepareCacheObjects(prevVals, cctx); if (forceTransformBackups) { // force addition of deployment info for entry processors if P2P is enabled globally. @@ -486,10 +486,10 @@ else if (conflictVers != null) invokeArgsBytes = Arrays.asList(marshalInvokeArguments(invokeArgs, cctx)); if (entryProcessorsBytes == null) - entryProcessorsBytes = marshalCollection(entryProcessors, cctx); + entryProcessorsBytes = marshalAndPrepareCollection(entryProcessors, cctx); if (nearEntryProcessorsBytes == null) - nearEntryProcessorsBytes = marshalCollection(nearEntryProcessors, cctx); + nearEntryProcessorsBytes = marshalAndPrepareCollection(nearEntryProcessors, cctx); } } 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..b241f6fbd9327 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 @@ -125,12 +125,8 @@ public void nearEvicted(List nearEvicted) { 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) + prepareCacheObjects(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..4a4c868148448 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 @@ -336,22 +336,10 @@ else if (conflictVers != null) if (expiryPlc != null && expiryPlcBytes == null) expiryPlcBytes = CU.marshal(cctx, new IgniteExternalizableExpiryPolicy(expiryPlc)); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjects(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 +347,13 @@ else if (conflictVers != null) addDepInfo = true; if (entryProcessorsBytes == null) - entryProcessorsBytes = marshalCollection(entryProcessors, cctx); + entryProcessorsBytes = marshalAndPrepareCollection(entryProcessors, cctx); if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) invokeArgsBytes = Arrays.asList(marshalInvokeArguments(invokeArgs, cctx)); } else - prepareMarshalCacheObjects(vals, cctx); + prepareCacheObjects(vals, cctx); } /** {@inheritDoc} */ 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..a5da3a9365838 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 @@ -95,22 +95,8 @@ public GridNearAtomicSingleUpdateFilterRequest() { @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; - } + if (filter != null && filter.length == 0) + filter = null; } /** {@inheritDoc} */ 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..67a18d83c7cd1 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 @@ -222,10 +222,10 @@ public GridNearAtomicSingleUpdateRequest() { GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObject(key, cctx); + prepareCacheObject(key, cctx); if (val != null) - prepareMarshalCacheObject(val, cctx); + prepareCacheObject(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..a66dc49a2deb8 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 @@ -344,14 +344,8 @@ synchronized void addFailedKeys(Collection keys, Throwable e) { 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); + prepareCacheObjects(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..c0bcb272a3fe2 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.prepareCacheObjects(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..93d12397cd442 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 @@ -119,7 +119,7 @@ public Collection keys() { GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjects(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..f4d14426e2e3d 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 @@ -138,12 +138,7 @@ public void addInfo(GridCacheEntryInfo info) { GridCacheContext cctx = ctx.cacheContext(cacheId); if (missedKeys != null) - prepareMarshalCacheObjects(missedKeys, cctx); - - if (infos != null) { - for (GridCacheEntryInfo info : infos) - info.marshal(cctx.cacheObjectContext()); - } + prepareCacheObjects(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..9a1944a721a04 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); + prepareInfo(info, ctx, cacheObjCtx); msgSize += info.marshalledSize(cacheObjCtx); 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..12432cbded298 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,7 +20,6 @@ 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; @@ -69,18 +68,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. 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..1ada1a83ed7af 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 @@ -293,7 +293,7 @@ public long accessTtl() { GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjects(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..2e27d2d16485e 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 @@ -257,7 +257,7 @@ public boolean recovery() { GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObject(key, cctx); + prepareCacheObject(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..8bdcfccb953f7 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 @@ -152,11 +152,7 @@ public long futureId() { 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); + prepareCacheObject((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..34b71de34bfb9 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 @@ -235,46 +235,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); 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..592cf335b2904 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 @@ -448,11 +448,6 @@ private static byte setDataPageScanEnabled(int flags, Boolean enabled) { idxQryDescBytes = CU.marshal(cctx, idxQryDesc); } - - if (!F.isEmpty(skipKeys)) { - for (KeyCacheObject k : skipKeys) - k.prepareMarshal(cctx.cacheObjectContext()); - } } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java index 6b295f2561182..da19ed40728e2 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 @@ -111,7 +111,7 @@ public GridCacheQueryResponse(int cacheId, long reqId, Throwable err, boolean ad GridCacheContext cctx = ctx.cacheContext(cacheId); if (dataBytes == null && data != null) - dataBytes = marshalCollection(data, cctx); + dataBytes = marshalAndPrepareCollection(data, cctx); if (addDepInfo && !F.isEmpty(data)) { for (Object o : data) { 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..70caf5f5342c9 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 @@ -295,21 +295,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. 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..45163be0b690b 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,29 +1023,13 @@ 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(); - - key.prepareMarshal(context().cacheObjectContext()); - - val.marshal(context()); + transferExpiryPlc = expiryPlc != null && expiryPlc != this.ctx.expiry(); if (transferExpiryPlc) { if (expiryPlcBytes == null) @@ -1051,9 +1037,10 @@ public void marshal(GridCacheSharedContext ctx, boolean transferExpiry) th } 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 29c5283c0af13..d5e2111cf3429 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 @@ -114,6 +114,7 @@ import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.lang.IgniteOutClosure; import org.apache.ignite.lang.IgniteReducer; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; import org.apache.ignite.spi.systemview.view.TransactionView; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; @@ -2430,8 +2431,14 @@ void txLocksInfo(UUID nodeId, TxDeadlockFuture fut, Set txKeys) { TxLocksRequest req = new TxLocksRequest(fut.futureId(), txKeys); try { - if (!cctx.localNodeId().equals(nodeId)) + if (!cctx.localNodeId().equals(nodeId)) { req.prepareMarshal(cctx); + + MessageSerializer ser = cctx.gridIO().messageFactory().serializer(req.directType()); + + if (ser != null) + ser.prepareMarshalCacheObjects(req, cctx, null); + } cctx.gridIO().sendToGridTopic(node, TOPIC_TX, req, 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..a3221cd2173ea 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 @@ -96,11 +96,8 @@ public Collection txKeys() { int i = 0; - for (IgniteTxKey key : txKeys) { - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - + for (IgniteTxKey key : txKeys) txKeysArr[i++] = key; - } } /** {@inheritDoc} */ 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..a00fa1be14032 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 @@ -151,8 +151,6 @@ public void addKey(IgniteTxKey key) { for (Map.Entry> entry : nearTxKeyLocks.entrySet()) { IgniteTxKey key = entry.getKey(); - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - nearTxKeysArr[i] = key; locksArr[i] = entry.getValue(); @@ -165,11 +163,8 @@ public void addKey(IgniteTxKey key) { int i = 0; - for (IgniteTxKey key : txKeys) { - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - + for (IgniteTxKey key : txKeys) txKeysArr[i++] = key; - } } } 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..102ac89ee7510 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 prepareMarshalCacheObjects(M msg, GridCacheSharedContext sctx, GridCacheContext nested) + throws IgniteCheckedException { + // No-op by default. + } } 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/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 diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java index 559f96bccad5c..d2db3800af5aa 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java @@ -42,12 +42,9 @@ public GridH2CacheObject() { /** * @param v Value. - * @throws IgniteCheckedException If failed. */ - public GridH2CacheObject(GridH2ValueCacheObject v) throws IgniteCheckedException { + public GridH2CacheObject(GridH2ValueCacheObject v) { obj = v.getCacheObject(); - - obj.prepareMarshal(v.valueContext()); } /** {@inheritDoc} */