com.hazelcast.config

## Class FlakeIdGeneratorConfig

- java.lang.Object
- - com.hazelcast.config.FlakeIdGeneratorConfig

- All Implemented Interfaces:
    DataSerializable, IdentifiedDataSerializable
  Direct Known Subclasses:
    FlakeIdGeneratorConfigReadOnly

      public class FlakeIdGeneratorConfig
      extends Object
      implements IdentifiedDataSerializable

  The `FlakeIdGeneratorConfig` contains the configuration for the member regarding `Flake ID Generator`.
  Since:
    3.10

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_PREFETCH_COUNT` Default value for `getPrefetchCount()`.
    `static long` | `DEFAULT_PREFETCH_VALIDITY_MILLIS` Default value for `getPrefetchValidityMillis()`.
    `static int` | `MAXIMUM_PREFETCH_COUNT` Maximum value for prefetch count.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)` Copy-constructor
    `FlakeIdGeneratorConfig(String name)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object o)`
    `FlakeIdGeneratorConfigReadOnly` | `getAsReadOnly()` Deprecated. this method will be removed in 4.0; it is meant for internal usage only
    `int` | `getFactoryId()` Returns DataSerializableFactory factory ID for this class.
    `int` | `getId()` Returns type identifier for this class.
    `long` | `getIdOffset()`
    `String` | `getName()` Returns the configuration name.
    `long` | `getNodeIdOffset()`
    `int` | `getPrefetchCount()`
    `long` | `getPrefetchValidityMillis()`
    `int` | `hashCode()`
    `boolean` | `isStatisticsEnabled()`
    `void` | `readData(ObjectDataInput in)` Reads fields from the input stream
    `FlakeIdGeneratorConfig` | `setIdOffset(long idOffset)` Sets the offset that will be added to the returned IDs.
    `void` | `setName(String name)` Sets the name or name pattern for this config.
    `FlakeIdGeneratorConfig` | `setNodeIdOffset(long nodeIdOffset)` Sets the offset that will be added to the node ID assigned to cluster member for this generator.
    `FlakeIdGeneratorConfig` | `setPrefetchCount(int prefetchCount)` Sets how many IDs are pre-fetched on the background when one call to `FlakeIdGenerator.newId()` is made.
    `FlakeIdGeneratorConfig` | `setPrefetchValidityMillis(long prefetchValidityMs)` Sets for how long the pre-fetched IDs can be used.
    `FlakeIdGeneratorConfig` | `setStatisticsEnabled(boolean statisticsEnabled)` Enables or disables statistics gathering of `LocalFlakeIdGeneratorStats`.
    `String` | `toString()`
    `void` | `writeData(ObjectDataOutput out)` Writes object fields to output stream

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_PREFETCH_COUNT

          public static final int DEFAULT_PREFETCH_COUNT

      Default value for `getPrefetchCount()`.
      See Also:
        Constant Field Values

    - #### DEFAULT_PREFETCH_VALIDITY_MILLIS

          public static final long DEFAULT_PREFETCH_VALIDITY_MILLIS

      Default value for `getPrefetchValidityMillis()`.
      See Also:
        Constant Field Values

    - #### MAXIMUM_PREFETCH_COUNT

          public static final int MAXIMUM_PREFETCH_COUNT

      Maximum value for prefetch count. The limit is ~10% of the time we allow the IDs to be from the future (see `FlakeIdGeneratorProxy.ALLOWED_FUTURE_MILLIS`).

      The reason to limit the prefetch count is that a single call to `FlakeIdGenerator.newId()` might be blocked if the future allowance is exceeded: we want to avoid a single call for large batch to block another call for small batch.

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FlakeIdGeneratorConfig

          public FlakeIdGeneratorConfig(String name)

    - #### FlakeIdGeneratorConfig

          public FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)

      Copy-constructor

  - ### Method Detail

    - #### getAsReadOnly

          public FlakeIdGeneratorConfigReadOnly getAsReadOnly()

      Deprecated. this method will be removed in 4.0; it is meant for internal usage only
      Gets immutable version of this configuration.
      Returns:
        immutable version of this configuration

    - #### getName

          public String getName()

      Returns the configuration name. This can be actual object name or pattern.

    - #### setName

          public void setName(String name)

      Sets the name or name pattern for this config. Must not be modified after this instance is added to `Config`.

    - #### getPrefetchCount

          public int getPrefetchCount()

      See Also:
        `setPrefetchCount(int)`

    - #### 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..100,000.
      Returns:
        this instance for fluent API

    - #### getPrefetchValidityMillis

          public long getPrefetchValidityMillis()

      See Also:
        `setPrefetchValidityMillis(long)`

    - #### 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

    - #### getIdOffset

          public long getIdOffset()

      See Also:
        `setIdOffset(long)`

    - #### setIdOffset

          public FlakeIdGeneratorConfig setIdOffset(long idOffset)

      Sets the offset that will be added to the returned IDs. Default value is 0. Setting might be useful when migrating from `IdGenerator`, default value works for all green-field projects.

      For example: Largest ID returned from `IdGenerator` is 150. `FlakeIdGenerator` now returns 100. If you configure `idOffset` of 50 and stop using the `IdGenerator`, the next ID from `FlakeIdGenerator` will be 151 or larger and no duplicate IDs will be generated. In real-life, the IDs are much larger. You also need to add a reserve to the offset because the IDs from `FlakeIdGenerator` are only roughly ordered. Recommended reserve is `1<<38`, that is 274877906944.

      Negative values are allowed to increase the lifespan of the generator, however keep in mind that the generated IDs might also be negative.

      Parameters:
        `idOffset` - the value added to each generated ID
      Returns:
        this instance for fluent API

    - #### getNodeIdOffset

          public long getNodeIdOffset()

      See Also:
        `setNodeIdOffset(long)`

    - #### 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`

    - #### isStatisticsEnabled

          public boolean isStatisticsEnabled()

      See Also:
        `setStatisticsEnabled(boolean)`

    - #### 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

    - #### getId

          public int getId()

      Description copied from interface: `IdentifiedDataSerializable`
      Returns type identifier for this class. It should be unique per DataSerializableFactory.
      Specified by:
        `getId` 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.

Copyright © 2020. All rights reserved.