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(org.lable.oss.dynamicconfig.zookeeper.MonitoringZookeeperConnection zooKeeperConnection,
String zNode,
int clusterId,
Supplier<Duration> claimDurationSupplier,
Supplier<Duration> acquisitionTimeoutSupplier) |
| 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,
Supplier<Duration> acquisitionTimeoutSupplier)
Create a new
SynchronizedGeneratorIdentity instance. |
void |
close() |
int |
getClusterId() |
int |
getGeneratorId() |
String |
getZNode() |
void |
relinquishGeneratorIdClaim() |
public static SynchronizedGeneratorIdentity basedOn(String quorum, String znode, Supplier<Duration> claimDurationSupplier, Supplier<Duration> acquisitionTimeoutSupplier) throws IOException
SynchronizedGeneratorIdentity instance.
By using a Supplier instead of static longs for the claim duration and the acquisition timeout, these
values can be dynamically reconfigured at runtime.
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.acquisitionTimeoutSupplier - Provides the amount of time the process of acquiring a generator-ID may take.
May be null to indicate that the process may wait indefinitely.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–2020 Lable. All rights reserved.