Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • All peers hold predefined messages schemas.
  • Messages follow schema in strict way - no fields are skipped and order of fields is guaranteed.
  • Peers send messages as byte stream serializing fields one by one, no delimiters are used between fields and messages.
  • For serializing POJO fields different techniques are used:
    • External marshaller Message consumes already serialized byte array (e.g. JdkMarshaller for IgniteDiagnosticMessage, SchemaOperationStatusMessage... BinaryMarshaller for GridJobExecuteRequest#jobBytes) - sender consumes serialized byte array to message.
    • User's BinaryObjects, Binarylizable are marshalled to byte array prior to serializing a message (the array is stored in cache structures).
    • Some messages contain POJO field annotated with GridDirectTransient, and additional byte array field fill with GridCacheMessage#prepareMarshal (e.g. BinaryMarshaller for GridChangeGlobalStateMessageResponse).

...

Code Block
languagejava
titleMyMessage
package org.apache.ignite.internal.messages;

// Message class DTO.
@Since(version = "2.19.0")
public class MyMessage {
    private int id;
    
 	/** Remove field. */
    @Until(version = "2.20.0")
    private String rmFld;

    /** New field. */
    @Since(version = "2.20.0")
    private String newFld;
}
    
// Generated code from the schema ^. 
package org.apache.ignite.internal.messages.codegen;

public class MyMessage {
    private int id;
    
	/**
     * Remove field. 
     * @deprecated since 2.20.0. 
     */
    @Deprecated
    private String rmFld;

    /** 
     * New field.
     * @since 2.20.0
     */
    private String newFld;

    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer, IgniteProductVersion destVer) {
        if (destVer.lessThan(2, 19, 0))
            throw new IgniteException("Must not send the message to destination node");

        if (!writer.writeString(id))
            return false;

        if (destVer.lessThan(2, 20, 0)) {
            if (!writer.writeString(rmFld))
                return false;
        }

        if (destVer.greaterThanEqual(2, 20, 0)) {
            if (!writer.writeString(newFld))
                return false;
        }

        return true;
    }

    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader, IgniteProductVersion srcVer) {
        id = reader.readString();

        if (srcVer.greaterThanEqual(2, 20, 0))
            newFld = reader.readString();
        else
            newFld = null;

        return true;
    }
}

...