public class SynchronizedUniqueIDGeneratorFactory extends Object
IDGenerator capable of generating unique identifiers in a distributed environment with multiple
services generating them. To do this, the GeneratorIdentityHolder it uses acquires a temporary claim on a
generator ID negotiated via a ZooKeeper quorum.
Because claimed generator IDs are automatically returned to the pool after a set time
(ExpiringResourceClaim.DEFAULT_TIMEOUT), there is no guarantee that IDs generated by the same
IDGenerator instance share the same generator ID.
| Constructor and Description |
|---|
SynchronizedUniqueIDGeneratorFactory() |
| Modifier and Type | Method and Description |
|---|---|
static IDGenerator |
generatorFor(SynchronizedGeneratorIdentity synchronizedGeneratorIdentity)
Get the synchronized ID generator instance.
|
static IDGenerator |
generatorFor(ZooKeeperConnection zooKeeperConnection,
String znode)
Get the synchronized ID generator instance.
|
public SynchronizedUniqueIDGeneratorFactory()
public static IDGenerator generatorFor(ZooKeeperConnection zooKeeperConnection, String znode) throws IOException
zooKeeperConnection - Connection to the ZooKeeper quorum.znode - Base-path of the resource pool in ZooKeeper.IOException - Thrown when something went wrong trying to find the cluster ID or trying to claim a
generator ID.public static IDGenerator generatorFor(SynchronizedGeneratorIdentity synchronizedGeneratorIdentity) throws IOException
synchronizedGeneratorIdentity - An instance of SynchronizedGeneratorIdentity to (re)use for
acquiring the generator ID.IOException - Thrown when something went wrong trying to find the cluster ID or trying to claim a
generator ID.Copyright © 2014–2017 Lable. All rights reserved.