Interface IdGeneratorDecorator
- All Superinterfaces:
Decorator<IdGenerator>
,IdGenerator
,Statistical
,StringIdGenerator
- All Known Implementing Classes:
ClockSyncSnowflakeId
,DefaultSnowflakeFriendlyId
,LazyIdGenerator
,MockIdGenerator
,StringIdGeneratorDecorator
,StringSegmentId
,StringSnowflakeId
,UncertaintyIdGenerator
This interface combines the IdGenerator
and Decorator
interfaces
to create a specialized decorator for ID generators. It allows implementations to
wrap existing ID generators and add additional functionality while maintaining
the full ID generation API.
Common use cases for ID generator decorators include:
- Custom ID conversion (using different
IdConverter
implementations) - Adding prefixes or suffixes to generated IDs
- Implementing caching or buffering of generated IDs
- Adding monitoring or logging capabilities
- Clock synchronization for time-based ID generators
Implementations of this interface are expected to be thread-safe and can be used concurrently across multiple threads.
-
Method Summary
Modifier and TypeMethodDescriptiondefault long
generate()
Generate a distributed ID by delegating to the actual generator.Get the actual (wrapped) ID generator that this decorator is enhancing.static <T extends IdGenerator>
TgetActual
(T idGenerator) Recursively get the actual ID generator from a potentially nested decorator chain.default IdGeneratorStat
stat()
Get statistical information about this decorated ID generator.Methods inherited from interface me.ahoo.cosid.IdGenerator
generateAsString, idConverter
-
Method Details
-
getActual
Get the actual (wrapped) ID generator that this decorator is enhancing.This method returns the underlying ID generator that this decorator is wrapping. All ID generation requests are typically delegated to this actual generator, with the decorator adding its additional functionality.
- Specified by:
getActual
in interfaceDecorator<IdGenerator>
- Returns:
- The actual ID generator being decorated
-
getActual
Recursively get the actual ID generator from a potentially nested decorator chain.This utility method traverses a chain of ID generator decorators to find the original undecorated ID generator. If the provided ID generator is a decorator, it will recursively call this method on the decorator's actual generator until it finds a non-decorator generator.
- Type Parameters:
T
- The type of the ID generator- Parameters:
idGenerator
- The ID generator to unwrap (may be a decorator or actual generator)- Returns:
- The unwrapped actual ID generator
-
generate
default long generate()Generate a distributed ID by delegating to the actual generator.This default implementation delegates the ID generation to the actual wrapped generator, ensuring that decorators can focus on adding functionality rather than reimplementing basic generation.
- Specified by:
generate
in interfaceIdGenerator
- Returns:
- A unique distributed ID as a long value
-
stat
Get statistical information about this decorated ID generator.This method provides combined statistical information from both the decorator itself and the actual generator it wraps, as well as the ID converter being used. This gives a complete picture of the generator's state.
- Specified by:
stat
in interfaceIdGenerator
- Specified by:
stat
in interfaceStatistical
- Returns:
- Statistical information about this decorated ID generator
-