public class DistributedIdGenerator extends Object
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 and Description |
|---|
DistributedIdGenerator(ZooKeeper zk,
String path,
String prefix) |
public DistributedIdGenerator(ZooKeeper zk, String path, String prefix) throws Exception
zk - path - path of the z-node used to track the generators idsprefix - prefix to prepend to the generated id. Having a unique prefix can make the id globally uniqueExceptionpublic String getNextId()
Copyright © 2017–2021 Apache Software Foundation. All rights reserved.