anton-vinogradov commented on code in PR #13095:
URL: https://github.com/apache/ignite/pull/13095#discussion_r3578928145
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java:
##########
@@ -262,370 +270,234 @@ public GridDeploymentInfoBean deployInfo() {
return depInfo;
}
- /**
- * This method is called before the whole message is serialized
- * and is responsible for pre-marshalling state.
- *
- * @param ctx Cache context.
- * @throws IgniteCheckedException If failed.
- */
- public void prepareMarshal(GridCacheSharedContext<?, ?> ctx) throws
IgniteCheckedException {
- // No-op.
- }
-
- /**
- * This method is called after the message is deserialized and is
responsible for
- * unmarshalling state marshalled in {@link
#prepareMarshal(GridCacheSharedContext)} method.
- *
- * @param ctx Context.
- * @param ldr Class loader.
- * @throws IgniteCheckedException If failed.
- */
- public void finishUnmarshal(GridCacheSharedContext<?, ?> ctx, ClassLoader
ldr) throws IgniteCheckedException {
- // No-op.
- }
-
/**
* @param info Entry to marshal.
* @param ctx Context.
* @param cacheObjCtx Cache object context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalInfo(GridCacheEntryInfo info,
+ public final void deployInfo(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);
+ deployObject(info.key().value(cacheObjCtx, false), ctx);
CacheObject val = info.value();
if (val != null) {
- val.finishUnmarshal(cacheObjCtx,
ctx.deploy().globalLoader());
+ val.unmarshal(cacheObjCtx, ctx.deploy().globalLoader());
- prepareObject(val.value(cacheObjCtx, false), ctx);
+ deployObject(val.value(cacheObjCtx, false), ctx);
}
}
}
}
- /**
- * @param info Entry to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
- * @throws IgniteCheckedException If failed.
- */
- protected final void unmarshalInfo(GridCacheEntryInfo info,
GridCacheContext ctx,
- ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
- if (info != null)
- info.unmarshal(ctx.cacheObjectContext(), ldr);
+ /** Deploys all {@code infos}, resolving shared and cache-object contexts
from {@code cctx}; no-op when {@code cctx} is absent. */
+ public final void deployInfos(@Nullable Iterable<? extends
GridCacheEntryInfo> infos, @Nullable GridCacheContext cctx)
+ throws IgniteCheckedException {
+ if (cctx != null)
+ deployInfos(infos, cctx.shared(), cctx.cacheObjectContext());
}
/**
* @param infos Entries to marshal.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalInfos(
- Iterable<? extends GridCacheEntryInfo> infos,
- GridCacheSharedContext ctx,
- CacheObjectContext cacheObjCtx
- ) throws IgniteCheckedException {
+ final void deployInfos(Iterable<? extends GridCacheEntryInfo> infos,
GridCacheSharedContext ctx,
+ CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
assert ctx != null;
if (infos != null)
for (GridCacheEntryInfo e : infos)
- marshalInfo(e, ctx, cacheObjCtx);
- }
-
- /**
- * @param infos Entries to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
- * @throws IgniteCheckedException If failed.
- */
- protected final void unmarshalInfos(Iterable<? extends GridCacheEntryInfo>
infos,
- GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
- if (infos != null)
- for (GridCacheEntryInfo e : infos)
- unmarshalInfo(e, ctx, ldr);
+ deployInfo(e, ctx, cacheObjCtx);
}
/**
* @param txEntries Entries to marshal.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalTx(Iterable<IgniteTxEntry> txEntries,
GridCacheSharedContext ctx)
+ public final void deployTx(Iterable<IgniteTxEntry> txEntries,
GridCacheSharedContext ctx)
throws IgniteCheckedException {
assert ctx != null;
if (txEntries != null) {
- boolean transferExpiry = transferExpiryPolicy();
boolean p2pEnabled = ctx.deploymentEnabled();
for (IgniteTxEntry e : txEntries) {
- e.marshal(ctx, transferExpiry);
-
GridCacheContext cctx = e.context();
if (addDepInfo) {
if (e.key() != null)
- prepareObject(e.key().value(cctx.cacheObjectContext(),
false), ctx);
+ deployObject(e.key().value(cctx.cacheObjectContext(),
false), ctx);
if (e.value() != null)
-
prepareObject(e.value().value(cctx.cacheObjectContext(), false), ctx);
+
deployObject(e.value().value(cctx.cacheObjectContext(), false), ctx);
if (e.entryProcessors() != null) {
for (T2<EntryProcessor<Object, Object, Object>,
Object[]> entProc : e.entryProcessors())
- prepareObject(entProc.get1(), ctx);
+ deployObject(entProc.get1(), ctx);
}
}
else if (p2pEnabled && e.entryProcessors() != null) {
if (!forceAddDepInfo)
forceAddDepInfo = true;
for (T2<EntryProcessor<Object, Object, Object>, Object[]>
entProc : e.entryProcessors())
- prepareObject(entProc.get1(), ctx);
+ deployObject(entProc.get1(), ctx);
}
}
}
}
/**
- * @return {@code True} if entries expire policy should be marshalled.
- */
- protected boolean transferExpiryPolicy() {
- return false;
- }
-
- /**
- * @param txEntries Entries to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
+ * @param args Arguments to marshal.
+ * @param marsh Marshaller.
+ * @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- protected final void unmarshalTx(Iterable<IgniteTxEntry> txEntries,
- GridCacheSharedContext ctx,
- ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
+ @Nullable protected final List<byte[]> marshallInvokeArguments(@Nullable
Object[] args, Marshaller marsh)
+ throws IgniteCheckedException {
- if (txEntries != null) {
- for (IgniteTxEntry e : txEntries) {
- e.prepareUnmarshal(ctx, topologyVersion(), false);
+ if (args == null || args.length == 0)
Review Comment:
Done.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java:
##########
@@ -262,370 +270,234 @@ public GridDeploymentInfoBean deployInfo() {
return depInfo;
}
- /**
- * This method is called before the whole message is serialized
- * and is responsible for pre-marshalling state.
- *
- * @param ctx Cache context.
- * @throws IgniteCheckedException If failed.
- */
- public void prepareMarshal(GridCacheSharedContext<?, ?> ctx) throws
IgniteCheckedException {
- // No-op.
- }
-
- /**
- * This method is called after the message is deserialized and is
responsible for
- * unmarshalling state marshalled in {@link
#prepareMarshal(GridCacheSharedContext)} method.
- *
- * @param ctx Context.
- * @param ldr Class loader.
- * @throws IgniteCheckedException If failed.
- */
- public void finishUnmarshal(GridCacheSharedContext<?, ?> ctx, ClassLoader
ldr) throws IgniteCheckedException {
- // No-op.
- }
-
/**
* @param info Entry to marshal.
* @param ctx Context.
* @param cacheObjCtx Cache object context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalInfo(GridCacheEntryInfo info,
+ public final void deployInfo(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);
+ deployObject(info.key().value(cacheObjCtx, false), ctx);
CacheObject val = info.value();
if (val != null) {
- val.finishUnmarshal(cacheObjCtx,
ctx.deploy().globalLoader());
+ val.unmarshal(cacheObjCtx, ctx.deploy().globalLoader());
- prepareObject(val.value(cacheObjCtx, false), ctx);
+ deployObject(val.value(cacheObjCtx, false), ctx);
}
}
}
}
- /**
- * @param info Entry to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
- * @throws IgniteCheckedException If failed.
- */
- protected final void unmarshalInfo(GridCacheEntryInfo info,
GridCacheContext ctx,
- ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
- if (info != null)
- info.unmarshal(ctx.cacheObjectContext(), ldr);
+ /** Deploys all {@code infos}, resolving shared and cache-object contexts
from {@code cctx}; no-op when {@code cctx} is absent. */
+ public final void deployInfos(@Nullable Iterable<? extends
GridCacheEntryInfo> infos, @Nullable GridCacheContext cctx)
+ throws IgniteCheckedException {
+ if (cctx != null)
+ deployInfos(infos, cctx.shared(), cctx.cacheObjectContext());
}
/**
* @param infos Entries to marshal.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalInfos(
- Iterable<? extends GridCacheEntryInfo> infos,
- GridCacheSharedContext ctx,
- CacheObjectContext cacheObjCtx
- ) throws IgniteCheckedException {
+ final void deployInfos(Iterable<? extends GridCacheEntryInfo> infos,
GridCacheSharedContext ctx,
+ CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
assert ctx != null;
if (infos != null)
for (GridCacheEntryInfo e : infos)
- marshalInfo(e, ctx, cacheObjCtx);
- }
-
- /**
- * @param infos Entries to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
- * @throws IgniteCheckedException If failed.
- */
- protected final void unmarshalInfos(Iterable<? extends GridCacheEntryInfo>
infos,
- GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
- if (infos != null)
- for (GridCacheEntryInfo e : infos)
- unmarshalInfo(e, ctx, ldr);
+ deployInfo(e, ctx, cacheObjCtx);
}
/**
* @param txEntries Entries to marshal.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalTx(Iterable<IgniteTxEntry> txEntries,
GridCacheSharedContext ctx)
+ public final void deployTx(Iterable<IgniteTxEntry> txEntries,
GridCacheSharedContext ctx)
throws IgniteCheckedException {
assert ctx != null;
if (txEntries != null) {
- boolean transferExpiry = transferExpiryPolicy();
boolean p2pEnabled = ctx.deploymentEnabled();
for (IgniteTxEntry e : txEntries) {
- e.marshal(ctx, transferExpiry);
-
GridCacheContext cctx = e.context();
if (addDepInfo) {
if (e.key() != null)
- prepareObject(e.key().value(cctx.cacheObjectContext(),
false), ctx);
+ deployObject(e.key().value(cctx.cacheObjectContext(),
false), ctx);
if (e.value() != null)
-
prepareObject(e.value().value(cctx.cacheObjectContext(), false), ctx);
+
deployObject(e.value().value(cctx.cacheObjectContext(), false), ctx);
if (e.entryProcessors() != null) {
for (T2<EntryProcessor<Object, Object, Object>,
Object[]> entProc : e.entryProcessors())
- prepareObject(entProc.get1(), ctx);
+ deployObject(entProc.get1(), ctx);
}
}
else if (p2pEnabled && e.entryProcessors() != null) {
if (!forceAddDepInfo)
forceAddDepInfo = true;
for (T2<EntryProcessor<Object, Object, Object>, Object[]>
entProc : e.entryProcessors())
- prepareObject(entProc.get1(), ctx);
+ deployObject(entProc.get1(), ctx);
}
}
}
}
/**
- * @return {@code True} if entries expire policy should be marshalled.
- */
- protected boolean transferExpiryPolicy() {
- return false;
- }
-
- /**
- * @param txEntries Entries to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
+ * @param args Arguments to marshal.
+ * @param marsh Marshaller.
+ * @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- protected final void unmarshalTx(Iterable<IgniteTxEntry> txEntries,
- GridCacheSharedContext ctx,
- ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
+ @Nullable protected final List<byte[]> marshallInvokeArguments(@Nullable
Object[] args, Marshaller marsh)
+ throws IgniteCheckedException {
- if (txEntries != null) {
- for (IgniteTxEntry e : txEntries) {
- e.prepareUnmarshal(ctx, topologyVersion(), false);
+ if (args == null || args.length == 0)
+ return null;
- e.unmarshal(ctx, false, ldr);
- }
- }
+ List<byte[]> argsBytes = new ArrayList<>(args.length);
+
+ for (Object arg : args)
+ argsBytes.add(arg == null ? null : U.marshal(marsh, arg));
+
+ return argsBytes;
}
/**
* @param args Arguments to marshal.
* @param ctx Context.
- * @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected final byte[][] marshalInvokeArguments(@Nullable
Object[] args, GridCacheContext ctx)
+ public final void deployInvokeArguments(@Nullable Object[] args, @Nullable
GridCacheContext ctx)
throws IgniteCheckedException {
- assert ctx != null;
-
- if (args == null || args.length == 0)
- return null;
-
- byte[][] argsBytes = new byte[args.length][];
+ if (ctx == null || args == null)
+ return;
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
if (addDepInfo)
- prepareObject(arg, ctx.shared());
-
- argsBytes[i] = arg == null ? null : CU.marshal(ctx, arg);
+ deployObject(arg, ctx.shared());
}
-
- return argsBytes;
}
-
/**
* @param byteCol Collection to unmarshal.
- * @param ctx Context.
+ * @param marsh Marshaller.
* @param ldr Loader.
* @return Unmarshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected final Object[] unmarshalInvokeArguments(@Nullable
byte[][] byteCol,
- GridCacheSharedContext ctx,
+ @Nullable protected final Object[] unmarshalInvokeArguments(@Nullable
List<byte[]> byteCol,
+ Marshaller marsh,
ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
if (byteCol == null)
return null;
- Object[] args = new Object[byteCol.length];
+ Object[] args = new Object[byteCol.size()];
- Marshaller marsh = ctx.marshaller();
+ int i = 0;
- for (int i = 0; i < byteCol.length; i++)
- args[i] = byteCol[i] == null ? null : U.unmarshal(marsh,
byteCol[i], U.resolveClassLoader(ldr, ctx.gridConfig()));
+ for (byte[] bytes : byteCol)
+ args[i++] = bytes == null ? null : U.unmarshal(marsh, bytes, ldr);
return args;
}
/**
* @param col Collection to marshal.
- * @param ctx Context.
+ * @param marsh Marshaller.
* @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected List<byte[]> marshalCollection(@Nullable Collection<?>
col,
- GridCacheContext ctx) throws IgniteCheckedException {
- assert ctx != null;
-
+ @Nullable protected List<byte[]> marshallCollection(@Nullable
Collection<?> col, Marshaller marsh) throws IgniteCheckedException {
if (col == null)
return null;
List<byte[]> byteCol = new ArrayList<>(col.size());
- for (Object o : col) {
- if (addDepInfo)
- prepareObject(o, ctx.shared());
-
- byteCol.add(o == null ? null : CU.marshal(ctx, o));
- }
+ for (Object o : col)
+ byteCol.add(o == null ? null : U.marshal(marsh, o));
return byteCol;
}
/**
- * @param col Collection.
- * @param ctx Cache context.
+ * Deploys each element of {@code col} via {@link #deployObject} on each
item.
+ *
+ * @param col Collection to marshal.
+ * @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- @SuppressWarnings("ForLoopReplaceableByForEach")
- public final void prepareMarshalCacheObjects(@Nullable List<? extends
CacheObject> col,
- GridCacheContext ctx) throws IgniteCheckedException {
- if (col == null)
+ public final void deployCollection(@Nullable Collection<?> col,
Review Comment:
Applied (covered by the file-wide generics sweep).
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java:
##########
@@ -262,370 +270,234 @@ public GridDeploymentInfoBean deployInfo() {
return depInfo;
}
- /**
- * This method is called before the whole message is serialized
- * and is responsible for pre-marshalling state.
- *
- * @param ctx Cache context.
- * @throws IgniteCheckedException If failed.
- */
- public void prepareMarshal(GridCacheSharedContext<?, ?> ctx) throws
IgniteCheckedException {
- // No-op.
- }
-
- /**
- * This method is called after the message is deserialized and is
responsible for
- * unmarshalling state marshalled in {@link
#prepareMarshal(GridCacheSharedContext)} method.
- *
- * @param ctx Context.
- * @param ldr Class loader.
- * @throws IgniteCheckedException If failed.
- */
- public void finishUnmarshal(GridCacheSharedContext<?, ?> ctx, ClassLoader
ldr) throws IgniteCheckedException {
- // No-op.
- }
-
/**
* @param info Entry to marshal.
* @param ctx Context.
* @param cacheObjCtx Cache object context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalInfo(GridCacheEntryInfo info,
+ public final void deployInfo(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);
+ deployObject(info.key().value(cacheObjCtx, false), ctx);
CacheObject val = info.value();
if (val != null) {
- val.finishUnmarshal(cacheObjCtx,
ctx.deploy().globalLoader());
+ val.unmarshal(cacheObjCtx, ctx.deploy().globalLoader());
- prepareObject(val.value(cacheObjCtx, false), ctx);
+ deployObject(val.value(cacheObjCtx, false), ctx);
}
}
}
}
- /**
- * @param info Entry to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
- * @throws IgniteCheckedException If failed.
- */
- protected final void unmarshalInfo(GridCacheEntryInfo info,
GridCacheContext ctx,
- ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
- if (info != null)
- info.unmarshal(ctx.cacheObjectContext(), ldr);
+ /** Deploys all {@code infos}, resolving shared and cache-object contexts
from {@code cctx}; no-op when {@code cctx} is absent. */
+ public final void deployInfos(@Nullable Iterable<? extends
GridCacheEntryInfo> infos, @Nullable GridCacheContext cctx)
+ throws IgniteCheckedException {
+ if (cctx != null)
+ deployInfos(infos, cctx.shared(), cctx.cacheObjectContext());
}
/**
* @param infos Entries to marshal.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalInfos(
- Iterable<? extends GridCacheEntryInfo> infos,
- GridCacheSharedContext ctx,
- CacheObjectContext cacheObjCtx
- ) throws IgniteCheckedException {
+ final void deployInfos(Iterable<? extends GridCacheEntryInfo> infos,
GridCacheSharedContext ctx,
+ CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
assert ctx != null;
if (infos != null)
for (GridCacheEntryInfo e : infos)
- marshalInfo(e, ctx, cacheObjCtx);
- }
-
- /**
- * @param infos Entries to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
- * @throws IgniteCheckedException If failed.
- */
- protected final void unmarshalInfos(Iterable<? extends GridCacheEntryInfo>
infos,
- GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
- if (infos != null)
- for (GridCacheEntryInfo e : infos)
- unmarshalInfo(e, ctx, ldr);
+ deployInfo(e, ctx, cacheObjCtx);
}
/**
* @param txEntries Entries to marshal.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalTx(Iterable<IgniteTxEntry> txEntries,
GridCacheSharedContext ctx)
+ public final void deployTx(Iterable<IgniteTxEntry> txEntries,
GridCacheSharedContext ctx)
throws IgniteCheckedException {
assert ctx != null;
if (txEntries != null) {
- boolean transferExpiry = transferExpiryPolicy();
boolean p2pEnabled = ctx.deploymentEnabled();
for (IgniteTxEntry e : txEntries) {
- e.marshal(ctx, transferExpiry);
-
GridCacheContext cctx = e.context();
if (addDepInfo) {
if (e.key() != null)
- prepareObject(e.key().value(cctx.cacheObjectContext(),
false), ctx);
+ deployObject(e.key().value(cctx.cacheObjectContext(),
false), ctx);
if (e.value() != null)
-
prepareObject(e.value().value(cctx.cacheObjectContext(), false), ctx);
+
deployObject(e.value().value(cctx.cacheObjectContext(), false), ctx);
if (e.entryProcessors() != null) {
for (T2<EntryProcessor<Object, Object, Object>,
Object[]> entProc : e.entryProcessors())
- prepareObject(entProc.get1(), ctx);
+ deployObject(entProc.get1(), ctx);
}
}
else if (p2pEnabled && e.entryProcessors() != null) {
if (!forceAddDepInfo)
forceAddDepInfo = true;
for (T2<EntryProcessor<Object, Object, Object>, Object[]>
entProc : e.entryProcessors())
- prepareObject(entProc.get1(), ctx);
+ deployObject(entProc.get1(), ctx);
}
}
}
}
/**
- * @return {@code True} if entries expire policy should be marshalled.
- */
- protected boolean transferExpiryPolicy() {
- return false;
- }
-
- /**
- * @param txEntries Entries to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
+ * @param args Arguments to marshal.
+ * @param marsh Marshaller.
+ * @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- protected final void unmarshalTx(Iterable<IgniteTxEntry> txEntries,
- GridCacheSharedContext ctx,
- ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
+ @Nullable protected final List<byte[]> marshallInvokeArguments(@Nullable
Object[] args, Marshaller marsh)
+ throws IgniteCheckedException {
- if (txEntries != null) {
- for (IgniteTxEntry e : txEntries) {
- e.prepareUnmarshal(ctx, topologyVersion(), false);
+ if (args == null || args.length == 0)
+ return null;
- e.unmarshal(ctx, false, ldr);
- }
- }
+ List<byte[]> argsBytes = new ArrayList<>(args.length);
+
+ for (Object arg : args)
+ argsBytes.add(arg == null ? null : U.marshal(marsh, arg));
+
+ return argsBytes;
}
/**
* @param args Arguments to marshal.
* @param ctx Context.
- * @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected final byte[][] marshalInvokeArguments(@Nullable
Object[] args, GridCacheContext ctx)
+ public final void deployInvokeArguments(@Nullable Object[] args, @Nullable
GridCacheContext ctx)
throws IgniteCheckedException {
- assert ctx != null;
-
- if (args == null || args.length == 0)
- return null;
-
- byte[][] argsBytes = new byte[args.length][];
+ if (ctx == null || args == null)
+ return;
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
if (addDepInfo)
- prepareObject(arg, ctx.shared());
-
- argsBytes[i] = arg == null ? null : CU.marshal(ctx, arg);
+ deployObject(arg, ctx.shared());
}
-
- return argsBytes;
}
-
/**
* @param byteCol Collection to unmarshal.
- * @param ctx Context.
+ * @param marsh Marshaller.
* @param ldr Loader.
* @return Unmarshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected final Object[] unmarshalInvokeArguments(@Nullable
byte[][] byteCol,
- GridCacheSharedContext ctx,
+ @Nullable protected final Object[] unmarshalInvokeArguments(@Nullable
List<byte[]> byteCol,
+ Marshaller marsh,
ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
if (byteCol == null)
return null;
- Object[] args = new Object[byteCol.length];
+ Object[] args = new Object[byteCol.size()];
- Marshaller marsh = ctx.marshaller();
+ int i = 0;
- for (int i = 0; i < byteCol.length; i++)
- args[i] = byteCol[i] == null ? null : U.unmarshal(marsh,
byteCol[i], U.resolveClassLoader(ldr, ctx.gridConfig()));
+ for (byte[] bytes : byteCol)
+ args[i++] = bytes == null ? null : U.unmarshal(marsh, bytes, ldr);
return args;
}
/**
* @param col Collection to marshal.
- * @param ctx Context.
+ * @param marsh Marshaller.
* @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected List<byte[]> marshalCollection(@Nullable Collection<?>
col,
- GridCacheContext ctx) throws IgniteCheckedException {
- assert ctx != null;
-
+ @Nullable protected List<byte[]> marshallCollection(@Nullable
Collection<?> col, Marshaller marsh) throws IgniteCheckedException {
if (col == null)
return null;
List<byte[]> byteCol = new ArrayList<>(col.size());
- for (Object o : col) {
- if (addDepInfo)
- prepareObject(o, ctx.shared());
-
- byteCol.add(o == null ? null : CU.marshal(ctx, o));
- }
+ for (Object o : col)
+ byteCol.add(o == null ? null : U.marshal(marsh, o));
return byteCol;
}
/**
- * @param col Collection.
- * @param ctx Cache context.
+ * Deploys each element of {@code col} via {@link #deployObject} on each
item.
+ *
+ * @param col Collection to marshal.
+ * @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- @SuppressWarnings("ForLoopReplaceableByForEach")
- public final void prepareMarshalCacheObjects(@Nullable List<? extends
CacheObject> col,
- GridCacheContext ctx) throws IgniteCheckedException {
- if (col == null)
+ public final void deployCollection(@Nullable Collection<?> col,
+ @Nullable GridCacheContext ctx) throws IgniteCheckedException {
+ if (ctx == null || col == null)
Review Comment:
Applied — and the same guard-hoist done in `deployInvokeArguments` for
consistency (plus its indexed loop became a for-each).
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java:
##########
@@ -262,370 +270,234 @@ public GridDeploymentInfoBean deployInfo() {
return depInfo;
}
- /**
- * This method is called before the whole message is serialized
- * and is responsible for pre-marshalling state.
- *
- * @param ctx Cache context.
- * @throws IgniteCheckedException If failed.
- */
- public void prepareMarshal(GridCacheSharedContext<?, ?> ctx) throws
IgniteCheckedException {
- // No-op.
- }
-
- /**
- * This method is called after the message is deserialized and is
responsible for
- * unmarshalling state marshalled in {@link
#prepareMarshal(GridCacheSharedContext)} method.
- *
- * @param ctx Context.
- * @param ldr Class loader.
- * @throws IgniteCheckedException If failed.
- */
- public void finishUnmarshal(GridCacheSharedContext<?, ?> ctx, ClassLoader
ldr) throws IgniteCheckedException {
- // No-op.
- }
-
/**
* @param info Entry to marshal.
* @param ctx Context.
* @param cacheObjCtx Cache object context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalInfo(GridCacheEntryInfo info,
+ public final void deployInfo(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);
+ deployObject(info.key().value(cacheObjCtx, false), ctx);
CacheObject val = info.value();
if (val != null) {
- val.finishUnmarshal(cacheObjCtx,
ctx.deploy().globalLoader());
+ val.unmarshal(cacheObjCtx, ctx.deploy().globalLoader());
- prepareObject(val.value(cacheObjCtx, false), ctx);
+ deployObject(val.value(cacheObjCtx, false), ctx);
}
}
}
}
- /**
- * @param info Entry to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
- * @throws IgniteCheckedException If failed.
- */
- protected final void unmarshalInfo(GridCacheEntryInfo info,
GridCacheContext ctx,
- ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
- if (info != null)
- info.unmarshal(ctx.cacheObjectContext(), ldr);
+ /** Deploys all {@code infos}, resolving shared and cache-object contexts
from {@code cctx}; no-op when {@code cctx} is absent. */
+ public final void deployInfos(@Nullable Iterable<? extends
GridCacheEntryInfo> infos, @Nullable GridCacheContext cctx)
+ throws IgniteCheckedException {
+ if (cctx != null)
+ deployInfos(infos, cctx.shared(), cctx.cacheObjectContext());
}
/**
* @param infos Entries to marshal.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalInfos(
- Iterable<? extends GridCacheEntryInfo> infos,
- GridCacheSharedContext ctx,
- CacheObjectContext cacheObjCtx
- ) throws IgniteCheckedException {
+ final void deployInfos(Iterable<? extends GridCacheEntryInfo> infos,
GridCacheSharedContext ctx,
+ CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
assert ctx != null;
if (infos != null)
for (GridCacheEntryInfo e : infos)
- marshalInfo(e, ctx, cacheObjCtx);
- }
-
- /**
- * @param infos Entries to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
- * @throws IgniteCheckedException If failed.
- */
- protected final void unmarshalInfos(Iterable<? extends GridCacheEntryInfo>
infos,
- GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
- if (infos != null)
- for (GridCacheEntryInfo e : infos)
- unmarshalInfo(e, ctx, ldr);
+ deployInfo(e, ctx, cacheObjCtx);
}
/**
* @param txEntries Entries to marshal.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void marshalTx(Iterable<IgniteTxEntry> txEntries,
GridCacheSharedContext ctx)
+ public final void deployTx(Iterable<IgniteTxEntry> txEntries,
GridCacheSharedContext ctx)
throws IgniteCheckedException {
assert ctx != null;
if (txEntries != null) {
- boolean transferExpiry = transferExpiryPolicy();
boolean p2pEnabled = ctx.deploymentEnabled();
for (IgniteTxEntry e : txEntries) {
- e.marshal(ctx, transferExpiry);
-
GridCacheContext cctx = e.context();
if (addDepInfo) {
if (e.key() != null)
- prepareObject(e.key().value(cctx.cacheObjectContext(),
false), ctx);
+ deployObject(e.key().value(cctx.cacheObjectContext(),
false), ctx);
if (e.value() != null)
-
prepareObject(e.value().value(cctx.cacheObjectContext(), false), ctx);
+
deployObject(e.value().value(cctx.cacheObjectContext(), false), ctx);
if (e.entryProcessors() != null) {
for (T2<EntryProcessor<Object, Object, Object>,
Object[]> entProc : e.entryProcessors())
- prepareObject(entProc.get1(), ctx);
+ deployObject(entProc.get1(), ctx);
}
}
else if (p2pEnabled && e.entryProcessors() != null) {
if (!forceAddDepInfo)
forceAddDepInfo = true;
for (T2<EntryProcessor<Object, Object, Object>, Object[]>
entProc : e.entryProcessors())
- prepareObject(entProc.get1(), ctx);
+ deployObject(entProc.get1(), ctx);
}
}
}
}
/**
- * @return {@code True} if entries expire policy should be marshalled.
- */
- protected boolean transferExpiryPolicy() {
- return false;
- }
-
- /**
- * @param txEntries Entries to unmarshal.
- * @param ctx Context.
- * @param ldr Loader.
+ * @param args Arguments to marshal.
+ * @param marsh Marshaller.
+ * @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- protected final void unmarshalTx(Iterable<IgniteTxEntry> txEntries,
- GridCacheSharedContext ctx,
- ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
+ @Nullable protected final List<byte[]> marshallInvokeArguments(@Nullable
Object[] args, Marshaller marsh)
+ throws IgniteCheckedException {
- if (txEntries != null) {
- for (IgniteTxEntry e : txEntries) {
- e.prepareUnmarshal(ctx, topologyVersion(), false);
+ if (args == null || args.length == 0)
+ return null;
- e.unmarshal(ctx, false, ldr);
- }
- }
+ List<byte[]> argsBytes = new ArrayList<>(args.length);
+
+ for (Object arg : args)
+ argsBytes.add(arg == null ? null : U.marshal(marsh, arg));
+
+ return argsBytes;
}
/**
* @param args Arguments to marshal.
* @param ctx Context.
- * @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected final byte[][] marshalInvokeArguments(@Nullable
Object[] args, GridCacheContext ctx)
+ public final void deployInvokeArguments(@Nullable Object[] args, @Nullable
GridCacheContext ctx)
throws IgniteCheckedException {
- assert ctx != null;
-
- if (args == null || args.length == 0)
- return null;
-
- byte[][] argsBytes = new byte[args.length][];
+ if (ctx == null || args == null)
+ return;
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
if (addDepInfo)
- prepareObject(arg, ctx.shared());
-
- argsBytes[i] = arg == null ? null : CU.marshal(ctx, arg);
+ deployObject(arg, ctx.shared());
}
-
- return argsBytes;
}
-
/**
* @param byteCol Collection to unmarshal.
- * @param ctx Context.
+ * @param marsh Marshaller.
* @param ldr Loader.
* @return Unmarshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected final Object[] unmarshalInvokeArguments(@Nullable
byte[][] byteCol,
- GridCacheSharedContext ctx,
+ @Nullable protected final Object[] unmarshalInvokeArguments(@Nullable
List<byte[]> byteCol,
+ Marshaller marsh,
ClassLoader ldr) throws IgniteCheckedException {
- assert ldr != null;
- assert ctx != null;
-
if (byteCol == null)
return null;
- Object[] args = new Object[byteCol.length];
+ Object[] args = new Object[byteCol.size()];
- Marshaller marsh = ctx.marshaller();
+ int i = 0;
- for (int i = 0; i < byteCol.length; i++)
- args[i] = byteCol[i] == null ? null : U.unmarshal(marsh,
byteCol[i], U.resolveClassLoader(ldr, ctx.gridConfig()));
+ for (byte[] bytes : byteCol)
+ args[i++] = bytes == null ? null : U.unmarshal(marsh, bytes, ldr);
return args;
}
/**
* @param col Collection to marshal.
- * @param ctx Context.
+ * @param marsh Marshaller.
* @return Marshalled collection.
* @throws IgniteCheckedException If failed.
*/
- @Nullable protected List<byte[]> marshalCollection(@Nullable Collection<?>
col,
- GridCacheContext ctx) throws IgniteCheckedException {
- assert ctx != null;
-
+ @Nullable protected List<byte[]> marshallCollection(@Nullable
Collection<?> col, Marshaller marsh) throws IgniteCheckedException {
if (col == null)
return null;
List<byte[]> byteCol = new ArrayList<>(col.size());
- for (Object o : col) {
- if (addDepInfo)
- prepareObject(o, ctx.shared());
-
- byteCol.add(o == null ? null : CU.marshal(ctx, o));
- }
+ for (Object o : col)
+ byteCol.add(o == null ? null : U.marshal(marsh, o));
return byteCol;
}
/**
- * @param col Collection.
- * @param ctx Cache context.
+ * Deploys each element of {@code col} via {@link #deployObject} on each
item.
+ *
+ * @param col Collection to marshal.
+ * @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- @SuppressWarnings("ForLoopReplaceableByForEach")
- public final void prepareMarshalCacheObjects(@Nullable List<? extends
CacheObject> col,
- GridCacheContext ctx) throws IgniteCheckedException {
- if (col == null)
+ public final void deployCollection(@Nullable Collection<?> col,
+ @Nullable GridCacheContext ctx) throws IgniteCheckedException {
+ if (ctx == null || col == null)
return;
- int size = col.size();
-
- for (int i = 0; i < size; i++)
- prepareMarshalCacheObject(col.get(i), ctx);
+ for (Object o : col) {
+ if (addDepInfo)
+ deployObject(o, ctx.shared());
+ }
}
/**
* @param obj Object.
* @param ctx Context.
* @throws IgniteCheckedException If failed.
*/
- protected final void prepareMarshalCacheObject(CacheObject obj,
GridCacheContext ctx) throws IgniteCheckedException {
- if (obj != null) {
- obj.prepareMarshal(ctx.cacheObjectContext());
-
- if (addDepInfo)
- prepareObject(obj.value(ctx.cacheObjectContext(), false),
ctx.shared());
- }
+ public final void deployCacheObject(@Nullable CacheObject obj, @Nullable
GridCacheContext ctx) throws IgniteCheckedException {
+ if (ctx != null && obj != null && addDepInfo)
+ deployObject(obj.value(ctx.cacheObjectContext(), false),
ctx.shared());
}
/**
* @param col Collection.
* @param ctx Cache context.
* @throws IgniteCheckedException If failed.
*/
- protected final void prepareMarshalCacheObjects(@Nullable Collection<?
extends CacheObject> col,
- GridCacheContext ctx) throws IgniteCheckedException {
- if (col == null)
+ public final void deployCacheObjects(@Nullable Collection<? extends
CacheObject> col,
+ @Nullable GridCacheContext ctx) throws IgniteCheckedException {
+ if (col == null || ctx == null)
Review Comment:
Applied.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]