Class FlakeIdGeneratorConfig
- java.lang.Object
-
- com.hazelcast.config.FlakeIdGeneratorConfig
-
- All Implemented Interfaces:
NamedConfig
,DataSerializable
,IdentifiedDataSerializable
public class FlakeIdGeneratorConfig extends java.lang.Object implements IdentifiedDataSerializable, NamedConfig
TheFlakeIdGeneratorConfig
contains the configuration for the member regardingFlake ID Generator
.- Since:
- 3.10
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_ALLOWED_FUTURE_MILLIS
Default value forgetAllowedFutureMillis()
.static int
DEFAULT_BITS_NODE_ID
Default value forgetBitsNodeId()
.static int
DEFAULT_BITS_SEQUENCE
Default value forgetBitsSequence()
.static long
DEFAULT_EPOCH_START
Default value forgetEpochStart()
.static int
DEFAULT_PREFETCH_COUNT
Default value forgetPrefetchCount()
.static long
DEFAULT_PREFETCH_VALIDITY_MILLIS
Default value forgetPrefetchValidityMillis()
.static int
MAXIMUM_PREFETCH_COUNT
Maximum value for prefetch count.
-
Constructor Summary
Constructors Constructor Description FlakeIdGeneratorConfig()
FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)
Copy-constructorFlakeIdGeneratorConfig(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
long
getAllowedFutureMillis()
int
getBitsNodeId()
int
getBitsSequence()
int
getClassId()
Returns type identifier for this class.long
getEpochStart()
int
getFactoryId()
Returns DataSerializableFactory factory ID for this class.java.lang.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 streamFlakeIdGeneratorConfig
setAllowedFutureMillis(long allowedFutureMillis)
Sets how far to the future is the generator allowed to go to generate IDs without blocking.FlakeIdGeneratorConfig
setBitsNodeId(int bitsNodeId)
Sets the bit-length of node id component.FlakeIdGeneratorConfig
setBitsSequence(int bitsSequence)
Sets the bit-length of the sequence component.FlakeIdGeneratorConfig
setEpochStart(long epochStart)
Sets the offset of timestamp component in milliseconds.FlakeIdGeneratorConfig
setName(java.lang.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 toFlakeIdGenerator.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 ofLocalFlakeIdGeneratorStats
.java.lang.String
toString()
void
writeData(ObjectDataOutput out)
Writes object fields to output stream
-
-
-
Field Detail
-
DEFAULT_PREFETCH_COUNT
public static final int DEFAULT_PREFETCH_COUNT
Default value forgetPrefetchCount()
.- See Also:
- Constant Field Values
-
DEFAULT_PREFETCH_VALIDITY_MILLIS
public static final long DEFAULT_PREFETCH_VALIDITY_MILLIS
Default value forgetPrefetchValidityMillis()
.- See Also:
- Constant Field Values
-
DEFAULT_EPOCH_START
public static final long DEFAULT_EPOCH_START
Default value forgetEpochStart()
.1514764800000
is the valueSystem.currentTimeMillis()
would return on 1.1.2018 0:00 UTC.- See Also:
- Constant Field Values
-
DEFAULT_BITS_SEQUENCE
public static final int DEFAULT_BITS_SEQUENCE
Default value forgetBitsSequence()
.- See Also:
- Constant Field Values
-
DEFAULT_BITS_NODE_ID
public static final int DEFAULT_BITS_NODE_ID
Default value forgetBitsNodeId()
.- See Also:
- Constant Field Values
-
DEFAULT_ALLOWED_FUTURE_MILLIS
public static final long DEFAULT_ALLOWED_FUTURE_MILLIS
Default value forgetAllowedFutureMillis()
.- 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 default time we allow the IDs to be from the future (seeDEFAULT_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 a large batch to block another call for a small batch.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FlakeIdGeneratorConfig
public FlakeIdGeneratorConfig()
-
FlakeIdGeneratorConfig
public FlakeIdGeneratorConfig(java.lang.String name)
-
FlakeIdGeneratorConfig
public FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)
Copy-constructor
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the configuration name. This can be actual object name or pattern.- Specified by:
getName
in interfaceNamedConfig
-
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 toConfig
.- Specified by:
setName
in interfaceNamedConfig
-
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 toFlakeIdGenerator.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(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
-
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. SeeFlakeIdGenerator
'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:
setEpochStart(long)
-
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
-
getBitsSequence
public int getBitsSequence()
- See Also:
setBitsSequence(int)
-
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. SeeFlakeIdGenerator
'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(int)
-
setBitsNodeId
public FlakeIdGeneratorConfig setBitsNodeId(int bitsNodeId)
Sets the bit-length of node id component. SeeFlakeIdGenerator
'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(long)
-
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(boolean)
-
setStatisticsEnabled
public FlakeIdGeneratorConfig setStatisticsEnabled(boolean statisticsEnabled)
Enables or disables statistics gathering ofLocalFlakeIdGeneratorStats
.- 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 classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getFactoryId
public int getFactoryId()
Description copied from interface:IdentifiedDataSerializable
Returns DataSerializableFactory factory ID for this class.- Specified by:
getFactoryId
in interfaceIdentifiedDataSerializable
- 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 interfaceIdentifiedDataSerializable
- Returns:
- type ID
-
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 interfaceDataSerializable
- Parameters:
out
- output- Throws:
java.io.IOException
- if an I/O error occurs. In particular, anIOException
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 interfaceDataSerializable
- Parameters:
in
- input- Throws:
java.io.IOException
- if an I/O error occurs. In particular, anIOException
may be thrown if the input stream has been closed.
-
-