Package me.ahoo.cosid.uncertainty
Class UncertaintyIdGenerator
java.lang.Object
me.ahoo.cosid.uncertainty.UncertaintyIdGenerator
- All Implemented Interfaces:
Decorator<IdGenerator>,IdGenerator,IdGeneratorDecorator,Statistical,StringIdGenerator
Uncertainty ID Generator.
For the following usage scenarios:
1. The problem of uneven sharding of snowflake IDs.
2. I don’t want the generated ID to be predictable, such as preventing crawler by ID number, predicting transaction volume.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlonggenerate()Generate a distributed ID by delegating to the actual generator.Get the actual (wrapped) ID generator that this decorator is enhancing.longintintlongMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.ahoo.cosid.IdGenerator
generateAsString, idConverterMethods inherited from interface me.ahoo.cosid.IdGeneratorDecorator
stat
-
Field Details
-
actual
-
-
Constructor Details
-
UncertaintyIdGenerator
-
-
Method Details
-
uncertaintyBits
public int uncertaintyBits() -
originalIdBits
public int originalIdBits() -
uncertaintyBound
public long uncertaintyBound() -
maxOriginalId
public long maxOriginalId() -
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
-
generate
public long generate()Description copied from interface:IdGeneratorDecoratorGenerate 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:
generatein interfaceIdGenerator- Specified by:
generatein interfaceIdGeneratorDecorator- Returns:
- A unique distributed ID as a long value
-