Class UncertaintyIdGenerator

java.lang.Object
me.ahoo.cosid.uncertainty.UncertaintyIdGenerator
All Implemented Interfaces:
Decorator<IdGenerator>, IdGenerator, IdGeneratorDecorator, Statistical, StringIdGenerator

@Beta public class UncertaintyIdGenerator extends Object implements IdGeneratorDecorator
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 Details

  • Constructor Details

    • UncertaintyIdGenerator

      public UncertaintyIdGenerator(IdGenerator actual, int uncertaintyBits)
  • Method Details

    • uncertaintyBits

      public int uncertaintyBits()
    • originalIdBits

      public int originalIdBits()
    • uncertaintyBound

      public long uncertaintyBound()
    • maxOriginalId

      public long maxOriginalId()
    • getActual

      @Nonnull public IdGenerator getActual()
      Description copied from interface: IdGeneratorDecorator
      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 interface Decorator<IdGenerator>
      Specified by:
      getActual in interface IdGeneratorDecorator
      Returns:
      The actual ID generator being decorated
    • generate

      public long generate()
      Description copied from interface: IdGeneratorDecorator
      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 interface IdGenerator
      Specified by:
      generate in interface IdGeneratorDecorator
      Returns:
      A unique distributed ID as a long value