Class DistributedIdGenerator


  • public class DistributedIdGenerator
    extends java.lang.Object
    Generate unique ids across multiple nodes.

    Each node has an instance of this class and uses the same z-node. At startup each node gets assigned a unique id, using ZK sequential nodes.

    After that, each node can just use a local counter and combine, the application prefix, its own instance id and with the counter incremental value to obtain a globally unique id.

    • Constructor Summary

      Constructors 
      Constructor Description
      DistributedIdGenerator​(org.apache.pulsar.metadata.api.coordination.CoordinationService cs, java.lang.String path, java.lang.String prefix)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getNextId()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DistributedIdGenerator

        public DistributedIdGenerator​(org.apache.pulsar.metadata.api.coordination.CoordinationService cs,
                                      java.lang.String path,
                                      java.lang.String prefix)
                               throws java.lang.Exception
        Parameters:
        cs - CoordinationService
        path - path of the z-node used to track the generators ids
        prefix - prefix to prepend to the generated id. Having a unique prefix can make the id globally unique
        Throws:
        java.lang.Exception
    • Method Detail

      • getNextId

        public java.lang.String getNextId()