Class MachineProperties
java.lang.Object
me.ahoo.cosid.spring.boot.starter.machine.MachineProperties
Configuration properties for machine ID management in distributed systems.
This class defines properties for configuring machine ID distribution, state storage, guarding mechanisms, and clock synchronization. These properties control how unique machine IDs are allocated and maintained across different instances in a cluster.
The configuration supports multiple distribution strategies:
- MANUAL - Explicitly configured machine ID
- STATEFUL_SET - Kubernetes StatefulSet-based allocation
- JDBC - Database-based distribution
- MONGO - MongoDB-based distribution
- REDIS - Redis-based distribution
- ZOOKEEPER - ZooKeeper-based distribution
- PROXY - Proxy service-based distribution
Example configuration:
cosid:
machine:
enabled: true
stable: true
instance-id: my-instance-01
distributor:
type: REDIS
redis:
timeout: 2s
guarder:
enabled: true
safe-guard-duration: 10m
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration for clock backwards synchronization.static classConfiguration for machine ID distribution strategies.static classConfiguration for machine ID guarding mechanisms.static classConfiguration for manual machine ID assignment.static classConfiguration for MongoDB-based machine ID distribution.static classConfiguration for Redis-based machine ID distribution.static classConfiguration for machine state storage mechanisms. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new MachineProperties instance with default configurations. -
Method Summary
Modifier and TypeMethodDescriptionGets the clock backwards configuration.Gets the distributor configuration.Gets the guarder configuration.Gets the unique instance identifier.intGets the number of bits allocated for machine ID.getPort()Gets the port number for this instance.Gets the effective safe guard duration based on guarder configuration.Gets whether the machine ID should be stable across restarts.Gets the state storage configuration.booleanChecks if machine ID management is enabled.voidsetClockBackwards(MachineProperties.ClockBackwards clockBackwards) Sets the clock backwards configuration.voidsetDistributor(MachineProperties.Distributor distributor) Sets the distributor configuration.voidsetEnabled(boolean enabled) Sets whether machine ID management should be enabled.setGuarder(MachineProperties.Guarder guarder) Sets the guarder configuration.voidsetInstanceId(String instanceId) Sets the unique instance identifier.voidsetMachineBit(int machineBit) Sets the number of bits allocated for machine ID.voidSets the port number for this instance.voidSets whether the machine ID should be stable across restarts.voidsetStateStorage(MachineProperties.StateStorage stateStorage) Sets the state storage configuration.
-
Field Details
-
PREFIX
The configuration property prefix for machine properties.- See Also:
-
-
Constructor Details
-
MachineProperties
public MachineProperties()Constructs a new MachineProperties instance with default configurations.Initializes all nested configuration objects with their default values.
-
-
Method Details
-
isEnabled
public boolean isEnabled()Checks if machine ID management is enabled.- Returns:
- true if enabled, false otherwise
-
setEnabled
public void setEnabled(boolean enabled) Sets whether machine ID management should be enabled.- Parameters:
enabled- true to enable, false to disable
-
getStable
Gets whether the machine ID should be stable across restarts.- Returns:
- true if stable, false if not, null if auto-determined
-
setStable
Sets whether the machine ID should be stable across restarts.- Parameters:
stable- true for stable, false for dynamic, null for auto-determination
-
getPort
Gets the port number for this instance.- Returns:
- the port number, or null if not set
-
setPort
Sets the port number for this instance.- Parameters:
port- the port number to set
-
getInstanceId
Gets the unique instance identifier.- Returns:
- the instance ID string, or null if not set
-
setInstanceId
Sets the unique instance identifier.- Parameters:
instanceId- the instance ID to set
-
getMachineBit
public int getMachineBit()Gets the number of bits allocated for machine ID.- Returns:
- the machine bit count
-
setMachineBit
public void setMachineBit(int machineBit) Sets the number of bits allocated for machine ID.- Parameters:
machineBit- the machine bit count to set
-
getStateStorage
Gets the state storage configuration.- Returns:
- the state storage configuration
-
setStateStorage
Sets the state storage configuration.- Parameters:
stateStorage- the state storage configuration to set
-
getDistributor
Gets the distributor configuration.- Returns:
- the distributor configuration
-
setDistributor
Sets the distributor configuration.- Parameters:
distributor- the distributor configuration to set
-
getGuarder
Gets the guarder configuration.- Returns:
- the guarder configuration
-
setGuarder
Sets the guarder configuration.- Parameters:
guarder- the guarder configuration to set- Returns:
- this properties instance for method chaining
-
getClockBackwards
Gets the clock backwards configuration.- Returns:
- the clock backwards configuration
-
setClockBackwards
Sets the clock backwards configuration.- Parameters:
clockBackwards- the clock backwards configuration to set
-
getSafeGuardDuration
Gets the effective safe guard duration based on guarder configuration.If the guarder is enabled, returns the configured safe guard duration. Otherwise, returns
MachineIdDistributor.FOREVER_SAFE_GUARD_DURATION.- Returns:
- the effective safe guard duration
-