public class SynchronizedGeneratorIdentity extends Object implements GeneratorIdentityHolder
GeneratorIdentityHolder that holds and reacquires when necessary a claim to a
generator-ID. When getGeneratorId() is called the generator-ID currently held by this object will be
returned. There is no guarantee that the same ID is returned on subsequent calls. Generator IDs should not be
cached or reused.| Constructor and Description |
|---|
SynchronizedGeneratorIdentity(ZooKeeperConnection zooKeeperConnection,
String zNode,
int clusterId,
Supplier<Duration> claimDurationSupplier) |
| Modifier and Type | Method and Description |
|---|---|
static SynchronizedGeneratorIdentity |
basedOn(String quorum,
String znode,
Long claimDuration)
Create a new
SynchronizedGeneratorIdentity instance. |
static SynchronizedGeneratorIdentity |
basedOn(String quorum,
String znode,
Supplier<Duration> claimDurationSupplier)
Create a new
SynchronizedGeneratorIdentity instance. |
void |
close() |
int |
getClusterId() |
int |
getGeneratorId() |
String |
getZNode() |
void |
relinquishGeneratorIdClaim() |
public SynchronizedGeneratorIdentity(ZooKeeperConnection zooKeeperConnection, String zNode, int clusterId, Supplier<Duration> claimDurationSupplier)
public static SynchronizedGeneratorIdentity basedOn(String quorum, String znode, Supplier<Duration> claimDurationSupplier) throws IOException
SynchronizedGeneratorIdentity instance.quorum - Addresses of the ZooKeeper quorum (comma-separated).znode - Root znode of the ZooKeeper resource-pool.claimDurationSupplier - Provides the amount of time a claim to a generator-ID should be held. By using a
Supplier instead of a static long, this may dynamically reconfigured at
runtime.SynchronizedGeneratorIdentity instance.IOExceptionpublic static SynchronizedGeneratorIdentity basedOn(String quorum, String znode, Long claimDuration) throws IOException
SynchronizedGeneratorIdentity instance.quorum - Addresses of the ZooKeeper quorum (comma-separated).znode - Root znode of the ZooKeeper resource-pool.claimDuration - How long a claim to a generator-ID should be held, in milliseconds.SynchronizedGeneratorIdentity instance.IOExceptionpublic int getClusterId()
throws GeneratorException
getClusterId in interface GeneratorIdentityHolderGeneratorExceptionpublic int getGeneratorId()
throws GeneratorException
getGeneratorId in interface GeneratorIdentityHolderGeneratorExceptionpublic String getZNode()
public void relinquishGeneratorIdClaim()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2014–2018 Lable. All rights reserved.