Class CompositeIDSource

  • All Implemented Interfaces:
    IDSource<Long>

    public final class CompositeIDSource
    extends Object
    implements IDSource<Long>

    Thread-safe source for partitioned unique IDs. A single instance of this class represents a single 'partition' in the space of possible IDs. By creating multiple instances with different discriminators, multiple entities may generate globally unique IDs independently.

    Any given instance of this class may generate a maximum of 2^31 unique values (the most significant 4 bytes are fixed and the least significant 4 bytes vary in sequence).

    • Constructor Detail

      • CompositeIDSource

        public CompositeIDSource​(int topPart)
        Parameters:
        topPart - The most significant 32 bits to use for the 64-bit IDs generated by this source. All IDs generated by this source will have the same top 4 bytes.
    • Method Detail

      • nextID

        public Long nextID()
        Implementing classes are responsible for synchronization if concurrent invocations of this method are required.
        Specified by:
        nextID in interface IDSource<Long>
        Returns:
        The next ID.