Class SegmentIdProperties

java.lang.Object
me.ahoo.cosid.spring.boot.starter.segment.SegmentIdProperties

@ConfigurationProperties(prefix="cosid.segment") public class SegmentIdProperties extends Object
Configuration properties for segment-based ID generation in Spring Boot applications.

This class defines properties for configuring segment ID generators, which provide high-performance, database-friendly ID generation. Segment IDs are allocated in batches (segments) to reduce database contention and improve performance.

The configuration supports different modes:

  • SEGMENT - Basic segment allocation
  • CHAIN - Chain-based segment allocation with prefetching

Multiple distributor types are supported for coordinating segment allocation:

  • REDIS - Redis-based coordination
  • JDBC - Database-based coordination
  • MONGO - MongoDB-based coordination
  • ZOOKEEPER - ZooKeeper-based coordination
  • PROXY - Proxy service-based coordination

Example configuration:


 cosid:
   segment:
     enabled: true
     mode: CHAIN
     ttl: 3600
     distributor:
       type: REDIS
       redis:
         timeout: 2s
 
  • Field Details

    • PREFIX

      public static final String PREFIX
      The configuration property prefix for segment ID properties.
      See Also:
  • Constructor Details

    • SegmentIdProperties

      public SegmentIdProperties()
      Constructs a new SegmentIdProperties instance with default configurations.

      Initializes all nested configuration objects with their default values.

  • Method Details

    • isEnabled

      public boolean isEnabled()
      Checks if segment ID generation is enabled.
      Returns:
      true if enabled, false otherwise
    • setEnabled

      public void setEnabled(boolean enabled)
      Sets whether segment ID generation should be enabled.
      Parameters:
      enabled - true to enable, false to disable
    • getMode

      public SegmentIdProperties.Mode getMode()
      Gets the mode of segment ID generation.
      Returns:
      the segment mode
    • setMode

      public void setMode(SegmentIdProperties.Mode mode)
      Sets the mode of segment ID generation.
      Parameters:
      mode - the segment mode to set
    • getTtl

      public long getTtl()
      Gets the time to live for ID segments.
      Returns:
      the TTL in seconds
    • setTtl

      public void setTtl(long ttl)
      Sets the time to live for ID segments.
      Parameters:
      ttl - the TTL in seconds to set
    • getDistributor

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

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

      public SegmentIdProperties.Chain getChain()
      Gets the chain configuration.
      Returns:
      the chain configuration
    • setChain

      public void setChain(SegmentIdProperties.Chain chain)
      Sets the chain configuration.
      Parameters:
      chain - the chain configuration to set
    • getShare

      Gets the shared ID definition configuration.
      Returns:
      the shared ID definition
    • setShare

      public void setShare(SegmentIdProperties.ShardIdDefinition share)
      Sets the shared ID definition configuration.
      Parameters:
      share - the shared ID definition to set
    • getProvider

      @Nonnull public Map<String,SegmentIdProperties.IdDefinition> getProvider()
      Gets the map of named ID definitions.
      Returns:
      the provider map of ID definitions
    • setProvider

      public void setProvider(Map<String,SegmentIdProperties.IdDefinition> provider)
      Sets the map of named ID definitions.
      Parameters:
      provider - the provider map to set