Class MachineProperties

java.lang.Object
me.ahoo.cosid.spring.boot.starter.machine.MachineProperties

@ConfigurationProperties(prefix="cosid.machine") public class MachineProperties extends Object
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
 
  • Field Details

  • 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

      public Boolean getStable()
      Gets whether the machine ID should be stable across restarts.
      Returns:
      true if stable, false if not, null if auto-determined
    • setStable

      public void setStable(Boolean stable)
      Sets whether the machine ID should be stable across restarts.
      Parameters:
      stable - true for stable, false for dynamic, null for auto-determination
    • getPort

      public Integer getPort()
      Gets the port number for this instance.
      Returns:
      the port number, or null if not set
    • setPort

      public void setPort(Integer port)
      Sets the port number for this instance.
      Parameters:
      port - the port number to set
    • getInstanceId

      public String getInstanceId()
      Gets the unique instance identifier.
      Returns:
      the instance ID string, or null if not set
    • setInstanceId

      public void setInstanceId(String instanceId)
      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

      public MachineProperties.StateStorage getStateStorage()
      Gets the state storage configuration.
      Returns:
      the state storage configuration
    • setStateStorage

      public void setStateStorage(MachineProperties.StateStorage stateStorage)
      Sets the state storage configuration.
      Parameters:
      stateStorage - the state storage configuration to set
    • getDistributor

      public MachineProperties.Distributor getDistributor()
      Gets the distributor configuration.
      Returns:
      the distributor configuration
    • setDistributor

      public void setDistributor(MachineProperties.Distributor distributor)
      Sets the distributor configuration.
      Parameters:
      distributor - the distributor configuration to set
    • getGuarder

      public MachineProperties.Guarder getGuarder()
      Gets the guarder configuration.
      Returns:
      the guarder configuration
    • setGuarder

      public MachineProperties setGuarder(MachineProperties.Guarder guarder)
      Sets the guarder configuration.
      Parameters:
      guarder - the guarder configuration to set
      Returns:
      this properties instance for method chaining
    • getClockBackwards

      public MachineProperties.ClockBackwards getClockBackwards()
      Gets the clock backwards configuration.
      Returns:
      the clock backwards configuration
    • setClockBackwards

      public void setClockBackwards(MachineProperties.ClockBackwards clockBackwards)
      Sets the clock backwards configuration.
      Parameters:
      clockBackwards - the clock backwards configuration to set
    • getSafeGuardDuration

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