Class CodeGeneratorBucket


  • public class CodeGeneratorBucket
    extends Object
    A code generation bucket provides a way to generate large numbers of random codes while minimizing collisions in the database. For example, - We want to generate a million codes - Since this could be a long(ish) running process, we want to do the database writes in batches - So, if we generate the database traffic in batches of 1000 we can avoid collisions of randomly generated numbers by reserving part of the code ("e.g. a bucket") that will be guaranteed not to collide. This works best when using unique code patterns for each large campaign involved with offers. Example: CAMPAIGN1-@@@@@@@@@@ where @@@@@@@ is the random part of the code.
    Author:
    bpolster
    • Field Detail

      • batchSize

        protected int batchSize
      • bucketIterationNumber

        protected int bucketIterationNumber
      • bucketsNeeded

        protected int bucketsNeeded
      • charsNeededForEachBucket

        protected int charsNeededForEachBucket
      • totalCharsInFormatForBucket

        protected int totalCharsInFormatForBucket
      • bucketPrefixCodePopulation

        protected long bucketPrefixCodePopulation
    • Method Detail

      • initializeBucket

        protected void initializeBucket()
        Prepares the bucket with data needed for code generation.
      • computeBaseDivisors

        protected int[] computeBaseDivisors()
        The base divisors are used to effectively determine the "base" of each character in the code. Think about this like decimal versus hex. The decimal base would (10,10,10, etc.) whereas the Hexadecimal base would be (16,16,16). Since we can have a variable number of possibilities per digit, this is more confusing when building codes. For example, the code pattern (##-@@) has 2 numbers, a dash, and 2 letters. Because we remove some numbers and letters from the available alphabet, the base divisors that would be computed for this example would be (7,7,23,23).
      • updateCodeFormatWithBucketPrefix

        public String updateCodeFormatWithBucketPrefix​(String codeFormat)
        Returns the passed in code after substituting the first "charNeededForEachBucket" in the code format with the appropriate bucket prefix.
        Parameters:
        codeFormat -
        Returns:
      • getBucketIterationNumber

        public int getBucketIterationNumber()
        Starts at one and is incremented each time a new bucket of codes has been generated.
        Returns:
      • getBucketsNeeded

        public int getBucketsNeeded()
      • updateBucketIteration

        public void updateBucketIteration()
      • determineBucketPrefixCodePopulation

        protected long determineBucketPrefixCodePopulation()
      • determineNumberOfCharsNeededForBuckets

        protected int determineNumberOfCharsNeededForBuckets()
        Returns the number of buckets of "batch size" needed to produce unique
        Returns: