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:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionConfigChange(ConfigChange.Type type, String nodeId, @Nullable String address) Compact constructor for validation. -
Method Summary
Modifier and TypeMethodDescription@Nullable Stringaddress()Returns the value of theaddressrecord component.static ConfigChangedeserialize(byte[] data) Deserialize a ConfigChange from a byte array.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanstatic booleanisConfigChange(byte[] data) Check if a byte array carries the ConfigChange header.booleanbooleanbooleannodeId()Returns the value of thenodeIdrecord component.byte[]Serialize to byte array for storage in Raft log.final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
Constructor Details
-
ConfigChange
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 nullIllegalArgumentException- 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
Deserialize a ConfigChange from a byte array.- Parameters:
data- the serialized data (non-null)- Returns:
- a new ConfigChange instance
- Throws:
NullPointerException- if data is nullIllegalArgumentException- if data format is invalid
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
type
-
nodeId
-
address
-