Package me.ahoo.cosid.provider
Class LazyIdGenerator
java.lang.Object
me.ahoo.cosid.provider.LazyIdGenerator
- All Implemented Interfaces:
Decorator<IdGenerator>,IdGenerator,IdGeneratorDecorator,Statistical,StringIdGenerator
Lazy loading IdGenerator.
Delays the lookup of an ID generator from the provider until first access. This is useful when the generator might not be immediately available at startup.
-
Constructor Summary
ConstructorsConstructorDescriptionLazyIdGenerator(String generatorName) Creates a lazy generator with default provider.LazyIdGenerator(String generatorName, IdGeneratorProvider idGeneratorProvider) Creates a lazy generator with custom provider. -
Method Summary
Modifier and TypeMethodDescriptionasFriendlyId(boolean required) Gets this generator as a SnowflakeFriendlyId.asSegmentId(boolean required) Gets this generator as a SegmentId.asSnowflakeId(boolean required) Gets this generator as a SnowflakeId.@NonNull IdGeneratorGet the actual (wrapped) ID generator that this decorator is enhancing.Gets the generator name.@NonNull IdConverterGet the ID converter used to convertlongtype IDs toString.tryGet(boolean required) Attempts to get the generator, optionally throwing if not found.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.ahoo.cosid.IdGenerator
generateAsStringMethods inherited from interface me.ahoo.cosid.IdGeneratorDecorator
generate, stat
-
Constructor Details
-
LazyIdGenerator
Creates a lazy generator with default provider.- Parameters:
generatorName- the name of the generator to lookup
-
LazyIdGenerator
Creates a lazy generator with custom provider.- Parameters:
generatorName- the name of the generator to lookupidGeneratorProvider- the provider to use for lookup
-
-
Method Details
-
getGeneratorName
Gets the generator name.- Returns:
- the generator name
-
tryGet
Attempts to get the generator, optionally throwing if not found.- Parameters:
required- if true, throws NotFoundIdGeneratorException if not found- Returns:
- the generator or null if not required and not found
- Throws:
NotFoundIdGeneratorException- if required and not found
-
asSnowflakeId
Gets this generator as a SnowflakeId.- Parameters:
required- if true, throws if not a SnowflakeId- Returns:
- the SnowflakeId or null
- Throws:
CosIdException- if not a SnowflakeId when required
-
asFriendlyId
Gets this generator as a SnowflakeFriendlyId.- Parameters:
required- if true, throws if not a SnowflakeFriendlyId- Returns:
- the SnowflakeFriendlyId or null
- Throws:
CosIdException- if not a SnowflakeFriendlyId when required
-
asSegmentId
Gets this generator as a SegmentId.- Parameters:
required- if true, throws if not a SegmentId- Returns:
- the SegmentId or null
- Throws:
CosIdException- if not a SegmentId when required
-
getActual
Description copied from interface:IdGeneratorDecoratorGet 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:
getActualin interfaceDecorator<IdGenerator>- Specified by:
getActualin interfaceIdGeneratorDecorator- Returns:
- The actual ID generator being decorated
-
idConverter
Description copied from interface:IdGeneratorGet the ID converter used to convertlongtype IDs toString.By default, this returns
Radix62IdConverter.PAD_STARTwhich converts long IDs to radix-62 string representations with padding to ensure consistent string lengths.- Specified by:
idConverterin interfaceIdGenerator- Returns:
- ID converter for transforming numeric IDs to string format
-