Class FlakeIdGeneratorConfig

    • Constructor Detail

      • FlakeIdGeneratorConfig

        public FlakeIdGeneratorConfig()
      • FlakeIdGeneratorConfig

        public FlakeIdGeneratorConfig​(java.lang.String name)
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the configuration name. This can be actual object name or pattern.
        Specified by:
        getName in interface NamedConfig
      • setName

        public FlakeIdGeneratorConfig setName​(java.lang.String name)
        Sets the name or name pattern for this config. Must not be modified after this instance is added to Config.
        Specified by:
        setName in interface NamedConfig
      • setPrefetchCount

        public FlakeIdGeneratorConfig setPrefetchCount​(int prefetchCount)
        Sets how many IDs are pre-fetched on the background when one call to FlakeIdGenerator.newId() is made. Default is 100.

        This setting pertains only to newId() calls made on the member that configured it.

        Parameters:
        prefetchCount - the desired prefetch count, in the range 1..100000.
        Returns:
        this instance for fluent API
      • setPrefetchValidityMillis

        public FlakeIdGeneratorConfig setPrefetchValidityMillis​(long prefetchValidityMs)
        Sets for how long the pre-fetched IDs can be used. If this time elapses, a new batch of IDs will be fetched. Time unit is milliseconds, default is 600,000 (10 minutes).

        The IDs contain timestamp component, which ensures rough global ordering of IDs. If an ID is assigned to an object that was created much later, it will be much out of order. If you don't care about ordering, set this value to 0.

        This setting pertains only to newId calls made on the member that configured it.

        Parameters:
        prefetchValidityMs - the desired ID validity or unlimited, if <=0
        Returns:
        this instance for fluent API
      • setEpochStart

        public FlakeIdGeneratorConfig setEpochStart​(long epochStart)
        Sets the offset of timestamp component in milliseconds. By default it's 1514764800000L, that is the beginning of 2018. You can adjust the value to determine the lifespan of the generator. See FlakeIdGenerator's class javadoc for more information.

        Note: If you set the epoch start to a future instant, negative IDs will be generated until that time occurs.

        Parameters:
        epochStart - the desired epoch start
        Returns:
        this instance for fluent API
        Since:
        4.0
      • setNodeIdOffset

        public FlakeIdGeneratorConfig setNodeIdOffset​(long nodeIdOffset)
        Sets the offset that will be added to the node ID assigned to cluster member for this generator. Might be useful in A/B deployment scenarios where you have cluster A which you want to upgrade. You create cluster B and for some time both will generate IDs and you want to have them unique. In this case, configure node ID offset for generators on cluster B.
        Parameters:
        nodeIdOffset - the value added to the node id
        Returns:
        this instance for fluent API
        See Also:
        for the node id logic
      • setBitsSequence

        public FlakeIdGeneratorConfig setBitsSequence​(int bitsSequence)
        Sets the bit-length of the sequence component. This setting determines the maximum rate at which IDs can be generated. See FlakeIdGenerator's class javadoc for more information.
        Parameters:
        bitsSequence - sequence component bit-length
        Returns:
        this instance for fluent API
        Since:
        4.0
      • setBitsNodeId

        public FlakeIdGeneratorConfig setBitsNodeId​(int bitsNodeId)
        Sets the bit-length of node id component. See FlakeIdGenerator's class javadoc for more information.
        Parameters:
        bitsNodeId - node id component bit-length
        Returns:
        this instance for fluent API
        Since:
        4.0
      • setAllowedFutureMillis

        public FlakeIdGeneratorConfig setAllowedFutureMillis​(long allowedFutureMillis)
        Sets how far to the future is the generator allowed to go to generate IDs without blocking.

        The number of bits configured for the sequence number (setBitsSequence(int) determines how many IDs can be generated per second. We allow the generator to generate IDs with future timestamps, and this settings limits how much. When more IDs are requested, the call will block. This is important in case of a cluster black-out or cluster restart: we don't store how far the members went and after they restart, they will start from current time. If before the restart the generator went beyond the current time, duplicate IDs could be generated.

        The default value is 15 seconds (15000). If your cluster is able to restart more quickly, set a lower value.

        See FlakeIdGenerator's class javadoc for more information.

        Parameters:
        allowedFutureMillis - value in milliseconds
        Returns:
        this instance for fluent API
        Since:
        4.0
      • setStatisticsEnabled

        public FlakeIdGeneratorConfig setStatisticsEnabled​(boolean statisticsEnabled)
        Enables or disables statistics gathering of LocalFlakeIdGeneratorStats.
        Parameters:
        statisticsEnabled - true if statistics gathering is enabled (which is also the default), false otherwise
        Returns:
        this instance for fluent API
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • writeData

        public void writeData​(ObjectDataOutput out)
                       throws java.io.IOException
        Description copied from interface: DataSerializable
        Writes object fields to output stream
        Specified by:
        writeData in interface DataSerializable
        Parameters:
        out - output
        Throws:
        java.io.IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
      • readData

        public void readData​(ObjectDataInput in)
                      throws java.io.IOException
        Description copied from interface: DataSerializable
        Reads fields from the input stream
        Specified by:
        readData in interface DataSerializable
        Parameters:
        in - input
        Throws:
        java.io.IOException - if an I/O error occurs. In particular, an IOException may be thrown if the input stream has been closed.