Record Class ConfigChange

java.lang.Object
java.lang.Record
com.loomcache.server.consensus.ConfigChange
Record Components:
type - the change type (non-null: ADD_SERVER, REMOVE_SERVER, LEARNER_ADD, LEARNER_REMOVE)
nodeId - the target node ID (non-null, non-blank)
address - the node address (non-blank for ADD_SERVER and LEARNER_ADD)

public record ConfigChange(ConfigChange.Type type, String nodeId, @Nullable String address) extends Record
Represents a single serialized membership-change command in the Raft cluster.

This record carries the intent that is stored in a CONFIG_CHANGE log entry. It does not, by itself, provide any membership-safety guarantees. Safety properties such as "one change at a time", learner catch-up before promotion, and which quorum must commit the entry are enforced by the caller that submits and applies the change.

Since:
1.0
See Also:
  • Constructor Details

    • ConfigChange

      public ConfigChange(ConfigChange.Type type, String nodeId, @Nullable String address)
      Compact constructor for validation. Ensures type is non-null, nodeId is non-null and non-blank, and address is non-blank for ADD_SERVER and LEARNER_ADD operations.
      Throws:
      NullPointerException - if type or nodeId is null
      IllegalArgumentException - if nodeId is blank or address is invalid
  • Method Details

    • isAddServer

      public boolean isAddServer()
    • isRemoveServer

      public boolean isRemoveServer()
    • isLearnerAdd

      public boolean isLearnerAdd()
    • isLearnerRemove

      public boolean isLearnerRemove()
    • serialize

      public byte[] serialize()
      Serialize to byte array for storage in Raft log. Format: 4 bytes (magic) + 1 byte (type) + 4 bytes (nodeId length) + nodeId bytes + 4 bytes (address length) + address bytes

      Returns:
      non-null serialized byte array
    • isConfigChange

      public static boolean isConfigChange(byte[] data)
      Check if a byte array carries the ConfigChange header.
      Parameters:
      data - the data to check
      Returns:
      true if data contains the ConfigChange magic header
    • deserialize

      public static ConfigChange deserialize(byte[] data)
      Deserialize a ConfigChange from a byte array.
      Parameters:
      data - the serialized data (non-null)
      Returns:
      a new ConfigChange instance
      Throws:
      NullPointerException - if data is null
      IllegalArgumentException - if data format is invalid
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • type

      public ConfigChange.Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • nodeId

      public String nodeId()
      Returns the value of the nodeId record component.
      Returns:
      the value of the nodeId record component
    • address

      public @Nullable String address()
      Returns the value of the address record component.
      Returns:
      the value of the address record component