Class IdGenerator


  • public class IdGenerator
    extends Object
    Generates numeric ID values for domain types. ID values are of the form xA+B, where x is the multiplier, A is an integer prefix, and B is the value of a counter incremented with each call. The use of a prefix allows the server to give each broker a space of ID values and prevent collisions.
    Author:
    John Collins
    • Constructor Detail

      • IdGenerator

        public IdGenerator()
    • Method Detail

      • createId

        public static long createId()
        Generates a numeric ID as xA+B.
      • setPrefix

        public static void setPrefix​(int value)
        Each entity living in a separate process must have a different prefix value. These values are presumably set by the competition control service.
      • getPrefix

        public static int getPrefix()
        Returns the id prefix - needed for testing.
      • getString

        public static String getString​(long id)
        Converts ID value to String as A.B.
      • getMultiplier

        public static int getMultiplier()
        Returns the multiplier for an id, needed to validate id values
      • extractPrefix

        public static int extractPrefix​(long id)
        Returns the id prefix for the given id.
      • recycle

        public static void recycle()
        Recycles the generator. This should only be used in a setting where multiple sessions are run in a single process.