public class SynchronizedUniqueIDGenerator extends BaseUniqueIDGenerator
BaseUniqueIDGenerator that coordinates the generator ID used by other processes
using this class via the same ZooKeeper quorum by attempting to claim an available ID for itself.
Although claims on a generator ID will be automatically relinquished after the connection to the ZooKeeper quorum
is lost, instances of this class should be explicitly closed after use, if you do not expect to generate anymore
IDs at that time.
Because claimed generator IDs are automatically returned to the pool after a set time
(ExpiringResourceClaim.DEFAULT_TIMEOUT),
there is no guarantee that IDs generated have the same generator ID.BaseUniqueIDGenerator.BlueprintclusterId, generatorId, MAX_CLUSTER_ID, MAX_GENERATOR_ID, MAX_SEQUENCE_COUNTER, MAX_TIMESTAMP| Modifier and Type | Method and Description |
|---|---|
byte[] |
generate() |
static SynchronizedUniqueIDGenerator |
generatorFor(String zookeeperQuorum,
String znode)
Get the synchronized ID generator instance.
|
void |
relinquishGeneratorIDClaim()
Return the claimed generator ID to the pool.
|
assertParameterWithinBounds, batch, parsepublic static SynchronizedUniqueIDGenerator generatorFor(String zookeeperQuorum, String znode) throws IOException
zookeeperQuorum - Addresses of the ZooKeeper quorum to connect to.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 byte[] generate()
throws GeneratorException
generate in interface IDGeneratorgenerate in class BaseUniqueIDGeneratorGeneratorExceptionpublic void relinquishGeneratorIDClaim()
Copyright © 2014–2015 Lable. All rights reserved.