anton-vinogradov commented on code in PR #13095:
URL: https://github.com/apache/ignite/pull/13095#discussion_r3588777680


##########
modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageMarshaller.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.plugin.extensions.communication;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.managers.communication.IgniteMessageFactory;
+import org.apache.ignite.internal.managers.communication.MessageUnmarshalDedup;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Handles {@code marshal}/{@code unmarshal} for a {@link Message} type that 
requires custom serialization.
+ *
+ * @param <M> Message type.
+ */
+public interface MessageMarshaller<M extends Message> {
+    /**
+     * Marshals the message on the user thread before sending.
+     *
+     * @param msg Message to marshal.
+     * @param kctx Kernal context.
+     * @param nested Cache object context, or {@code null} if not applicable.
+     */
+    public void marshal(M msg, GridKernalContext kctx, @Nullable 
CacheObjectContext nested)
+        throws IgniteCheckedException;
+
+    /**
+     * Unmarshals the message with full cache context and class loader.
+     *
+     * @param msg Message to unmarshal.
+     * @param kctx Kernal context.
+     * @param nested Cache object context, or {@code null} if not applicable.
+     * @param clsLdr Class loader for unmarshalling.
+     */
+    public void unmarshal(M msg, GridKernalContext kctx, @Nullable 
CacheObjectContext nested, ClassLoader clsLdr)
+        throws IgniteCheckedException;
+
+    /**
+     * Unmarshals the message without a cache context, using the configuration 
class loader — the cache-free receive
+     * path (e.g. the generic {@code GridIoManager} pass). Delegates to the 
cache-aware overload with a {@code null}
+     * context, so per-message marshallers need only implement the cache-aware 
method.
+     *
+     * @param msg Message to unmarshal.
+     * @param kctx Kernal context.
+     */
+    default void unmarshal(M msg, GridKernalContext kctx) throws 
IgniteCheckedException {
+        unmarshal(msg, kctx, null, U.resolveClassLoader(kctx.config()));
+    }
+
+    /**
+     * Unmarshals only {@code @NioField}-annotated fields in the NIO/IO 
thread. No-op by default.
+     *
+     * @param msg Message to unmarshal.
+     * @param kctx Kernal context.
+     */
+    default void unmarshalNio(M msg, GridKernalContext kctx) throws 
IgniteCheckedException {
+    }
+
+    /**
+     * Null-safe {@code unmarshalNio} — skips when no marshaller is registered.
+     *
+     * @param <M> Message type.
+     * @param factory Message factory.
+     * @param msg Message to unmarshal.
+     * @param kctx Kernal context.
+     */
+    static <M extends Message> void unmarshalNio(MessageFactory factory, M 
msg, GridKernalContext kctx)

Review Comment:
   Done — you're right, refactored rather than stopping at the compile 
constraint. The four resolve-and-dispatch statics moved out of the 
`MessageMarshaller` interface into a new `MessageMarshalling` util in 
`o.a.i.internal.managers.communication`, and they now derive the factory from 
`kctx.messageFactory()` instead of taking it as a parameter. The interface 
keeps only the instance methods. All ~27 call sites (production + tests), the 
generator emission, and the goldens are updated; the ArchUnit rule now exempts 
`MessageMarshalling` (it legitimately calls the instance methods) and points 
callers at it. Verified: MessageProcessorTest goldens 34/34, 
MessageSerializationArchitectureTest 3/3, marshal/unmarshal-once, QueryEntity 
round-trip, DiscoveryUnmarshalVulnerabilityTest 7/7; checkstyle clean.



-- 
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]

Reply via email to