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


##########
modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java:
##########
@@ -38,4 +38,36 @@ public interface MessageSerializer<M extends Message> {
      * @return Whether message was fully read.
      */
     public boolean readFrom(M msg, MessageReader reader);
+
+    /**
+     * Writes the message using the serializer resolved from the factory.
+     *
+     * @param factory Message factory.
+     * @param msg Message instance.
+     * @param writer Writer.
+     * @param <M> Message type.
+     * @return Whether message was fully written.
+     */
+    static <M extends Message> boolean writeTo(MessageFactory factory, M msg, 
MessageWriter writer) {

Review Comment:
   They're the family-wide pattern: instance methods are the per-type generated 
implementations, while the interface statics are the resolve-and-dispatch entry 
point — same as `MessageMarshaller.marshal/unmarshal` and 
`GridCacheMessageDeployer.deploy`. A separate `SerializationUtil` would split 
the contract and its entry point across two types, and an abstract class isn't 
an option — this is an interface-based SPI implemented by the generated 
serializers. The statics are also the *enforced* entry: 
`MessageSerializationArchitectureTest` (ArchUnit) fails any direct 
instance-method call.



##########
modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java:
##########
@@ -38,4 +38,36 @@ public interface MessageSerializer<M extends Message> {
      * @return Whether message was fully read.
      */
     public boolean readFrom(M msg, MessageReader reader);
+
+    /**
+     * Writes the message using the serializer resolved from the factory.
+     *
+     * @param factory Message factory.
+     * @param msg Message instance.
+     * @param writer Writer.
+     * @param <M> Message type.
+     * @return Whether message was fully written.
+     */
+    static <M extends Message> boolean writeTo(MessageFactory factory, M msg, 
MessageWriter writer) {
+        return resolve(factory, msg).writeTo(msg, writer);
+    }
+
+    /**
+     * Reads the message using the serializer resolved from the factory.
+     *
+     * @param factory Message factory.
+     * @param msg Message instance.
+     * @param reader Reader.
+     * @param <M> Message type.
+     * @return Whether message was fully read.
+     */
+    static <M extends Message> boolean readFrom(MessageFactory factory, M msg, 
MessageReader reader) {
+        return resolve(factory, msg).readFrom(msg, reader);
+    }
+
+    /** @return the serializer registered for {@code msg}'s direct type. */
+    @SuppressWarnings("unchecked")
+    private static <M extends Message> MessageSerializer<M> 
resolve(MessageFactory factory, M msg) {

Review Comment:
   It's actually called from a dozen production sites — `GridNioServer`, 
`GridDirectParser`, `DirectByteBufferStream`, `TcpHandshakeExecutor`, 
`TcpDiscoveryIoSession`, the ZK `DiscoveryMessageParser` (the private `resolve` 
below is the interface-internal one). Rationale for statics-on-interface — see 
the sibling thread above.



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