Package org.lable.oss.uniqueid.etcd
Class SynchronizedUniqueIDGeneratorFactory
- java.lang.Object
-
- org.lable.oss.uniqueid.etcd.SynchronizedUniqueIDGeneratorFactory
-
public class SynchronizedUniqueIDGeneratorFactory extends Object
Create anIDGeneratorcapable of generating unique identifiers in a distributed environment with multiple services generating them. To do this, theGeneratorIdentityHolderit uses acquires a temporary claim on a generator ID negotiated via an Etcd cluster.Because claimed generator IDs are automatically returned to the pool after a set time (
ExpiringResourceClaim.DEFAULT_CLAIM_HOLD), there is no guarantee that IDs generated by the sameIDGeneratorinstance share the same generator ID.
-
-
Constructor Summary
Constructors Constructor Description SynchronizedUniqueIDGeneratorFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IDGeneratorgeneratorFor(io.etcd.jetcd.Client etcd, Mode mode)Get the synchronized ID generator instance.static IDGeneratorgeneratorFor(io.etcd.jetcd.Client etcd, Clock clock, Mode mode)Get the synchronized ID generator instance.static IDGeneratorgeneratorFor(SynchronizedGeneratorIdentity synchronizedGeneratorIdentity, Clock clock, Mode mode)Get the synchronized ID generator instance.
-
-
-
Method Detail
-
generatorFor
public static IDGenerator generatorFor(io.etcd.jetcd.Client etcd, Clock clock, Mode mode) throws IOException
Get the synchronized ID generator instance.- Parameters:
etcd- Connection to the Etcd cluster.clock- Clock implementation.mode- Generator mode.- Returns:
- An instance of this class.
- Throws:
IOException- Thrown when something went wrong trying to find the cluster ID or trying to claim a generator ID.
-
generatorFor
public static IDGenerator generatorFor(io.etcd.jetcd.Client etcd, Mode mode) throws IOException
Get the synchronized ID generator instance.- Parameters:
etcd- Connection to the Etcd cluster.mode- Generator mode.- Returns:
- An instance of this class.
- Throws:
IOException- Thrown when something went wrong trying to find the cluster ID or trying to claim a generator ID.
-
generatorFor
public static IDGenerator generatorFor(SynchronizedGeneratorIdentity synchronizedGeneratorIdentity, Clock clock, Mode mode)
Get the synchronized ID generator instance.- Parameters:
synchronizedGeneratorIdentity- An instance ofSynchronizedGeneratorIdentityto (re)use for acquiring the generator ID.clock- Clock implementation.mode- Generator mode.- Returns:
- An instance of this class.
-
-