Class SynchronizedUniqueIDGeneratorFactory


  • public class SynchronizedUniqueIDGeneratorFactory
    extends Object
    Create an IDGenerator capable of generating unique identifiers in a distributed environment with multiple services generating them. To do this, the GeneratorIdentityHolder it 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 same IDGenerator instance share the same generator ID.

    • Constructor Detail

      • SynchronizedUniqueIDGeneratorFactory

        public SynchronizedUniqueIDGeneratorFactory()
    • 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 of SynchronizedGeneratorIdentity to (re)use for acquiring the generator ID.
        clock - Clock implementation.
        mode - Generator mode.
        Returns:
        An instance of this class.