Class SegmentIdProperties
java.lang.Object
me.ahoo.cosid.spring.boot.starter.segment.SegmentIdProperties
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration for chain-based segment ID generation.static classstatic classstatic enumEnumeration of supported segment ID generation modes.static class -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new SegmentIdProperties instance with default configurations. -
Method Summary
Modifier and TypeMethodDescriptiongetChain()Gets the chain configuration.Gets the distributor configuration.getMode()Gets the mode of segment ID generation.Gets the map of named ID definitions.getShare()Gets the shared ID definition configuration.longgetTtl()Gets the time to live for ID segments.booleanChecks if segment ID generation is enabled.voidSets the chain configuration.voidsetDistributor(SegmentIdProperties.Distributor distributor) Sets the distributor configuration.voidsetEnabled(boolean enabled) Sets whether segment ID generation should be enabled.voidSets the mode of segment ID generation.voidsetProvider(Map<String, SegmentIdProperties.IdDefinition> provider) Sets the map of named ID definitions.voidSets the shared ID definition configuration.voidsetTtl(long ttl) Sets the time to live for ID segments.
-
Field Details
-
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
Gets the mode of segment ID generation.- Returns:
- the segment mode
-
setMode
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
Gets the distributor configuration.- Returns:
- the distributor configuration
-
setDistributor
Sets the distributor configuration.- Parameters:
distributor- the distributor configuration to set
-
getChain
Gets the chain configuration.- Returns:
- the chain configuration
-
setChain
Sets the chain configuration.- Parameters:
chain- the chain configuration to set
-
getProvider
Gets the map of named ID definitions.- Returns:
- the provider map of ID definitions
-
setProvider
Sets the map of named ID definitions.- Parameters:
provider- the provider map to set
-