Class FlakeIdGeneratorConfig

java.lang.Object
com.hazelcast.config.FlakeIdGeneratorConfig
All Implemented Interfaces:
NamedConfig, DataSerializable, IdentifiedDataSerializable

public class FlakeIdGeneratorConfig extends Object implements IdentifiedDataSerializable, NamedConfig
The FlakeIdGeneratorConfig contains the configuration for the member regarding Flake ID Generator.
Since:
3.10
  • Field Details

  • Constructor Details

    • FlakeIdGeneratorConfig

      public FlakeIdGeneratorConfig()
    • FlakeIdGeneratorConfig

      public FlakeIdGeneratorConfig(String name)
    • FlakeIdGeneratorConfig

      public FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)
      Copy-constructor
  • Method Details

    • getName

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

      public FlakeIdGeneratorConfig setName(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
    • getPrefetchCount

      public int getPrefetchCount()
      See Also:
    • 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
    • getPrefetchValidityMillis

      public long getPrefetchValidityMillis()
      See Also:
    • 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
    • getEpochStart

      public long getEpochStart()
      See Also:
    • getNodeIdOffset

      public long getNodeIdOffset()
      See Also:
    • 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:
    • getBitsSequence

      public int getBitsSequence()
      See Also:
    • 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
    • getBitsNodeId

      public int getBitsNodeId()
      See Also:
    • 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
    • getAllowedFutureMillis

      public long getAllowedFutureMillis()
      See Also:
    • 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
    • isStatisticsEnabled

      public boolean isStatisticsEnabled()
      See Also:
    • 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(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object
    • getFactoryId

      public int getFactoryId()
      Description copied from interface: IdentifiedDataSerializable
      Returns DataSerializableFactory factory ID for this class.
      Specified by:
      getFactoryId in interface IdentifiedDataSerializable
      Returns:
      factory ID
    • getClassId

      public int getClassId()
      Description copied from interface: IdentifiedDataSerializable
      Returns type identifier for this class. It should be unique per DataSerializableFactory.
      Specified by:
      getClassId in interface IdentifiedDataSerializable
      Returns:
      type ID
    • writeData

      public void writeData(ObjectDataOutput out) throws IOException
      Description copied from interface: DataSerializable
      Writes object fields to output stream
      Specified by:
      writeData in interface DataSerializable
      Parameters:
      out - output
      Throws:
      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 IOException
      Description copied from interface: DataSerializable
      Reads fields from the input stream
      Specified by:
      readData in interface DataSerializable
      Parameters:
      in - input
      Throws:
      IOException - if an I/O error occurs. In particular, an IOException may be thrown if the input stream has been closed.