Package org.lable.oss.uniqueid.etcd
Class SynchronizedGeneratorIdentity
- java.lang.Object
-
- org.lable.oss.uniqueid.etcd.SynchronizedGeneratorIdentity
-
- All Implemented Interfaces:
Closeable,AutoCloseable,GeneratorIdentityHolder
public class SynchronizedGeneratorIdentity extends Object implements GeneratorIdentityHolder
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SynchronizedGeneratorIdentitybasedOn(String endpoints, String namespace, Long claimDuration)Create a newSynchronizedGeneratorIdentityinstance.static SynchronizedGeneratorIdentitybasedOn(String endpoints, String namespace, Supplier<Duration> claimDurationSupplier, Supplier<Duration> acquisitionTimeoutSupplier)Create a newSynchronizedGeneratorIdentityinstance.voidclose()intgetClusterId()intgetGeneratorId()voidrelinquishResourceClaim()
-
-
-
Method Detail
-
basedOn
public static SynchronizedGeneratorIdentity basedOn(String endpoints, String namespace, Supplier<Duration> claimDurationSupplier, Supplier<Duration> acquisitionTimeoutSupplier) throws IOException
Create a newSynchronizedGeneratorIdentityinstance.By using a
Supplierinstead of static longs for the claim duration and the acquisition timeout, these values can be dynamically reconfigured at runtime.- Parameters:
endpoints- Addresses of the Etcd cluster (comma-separated).namespace- Namespace of the unique-id keys in Etcd.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 benullto indicate that the process may wait indefinitely.- Returns:
- A
SynchronizedGeneratorIdentityinstance. - Throws:
IOException
-
basedOn
public static SynchronizedGeneratorIdentity basedOn(String endpoints, String namespace, Long claimDuration) throws IOException
Create a newSynchronizedGeneratorIdentityinstance.- Parameters:
endpoints- Addresses of the Etcd cluster (comma-separated).namespace- Namespace of the unique-id keys in Etcd.claimDuration- How long a claim to a generator-ID should be held, in milliseconds.- Returns:
- A
SynchronizedGeneratorIdentityinstance. - Throws:
IOException
-
getClusterId
public int getClusterId() throws GeneratorException- Specified by:
getClusterIdin interfaceGeneratorIdentityHolder- Throws:
GeneratorException
-
getGeneratorId
public int getGeneratorId() throws GeneratorException- Specified by:
getGeneratorIdin interfaceGeneratorIdentityHolder- Throws:
GeneratorException
-
relinquishResourceClaim
public void relinquishResourceClaim()
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-