public class FlakeIdGeneratorConfig extends Object implements IdentifiedDataSerializable, NamedConfig
FlakeIdGeneratorConfig
contains the configuration for the member
regarding Flake ID Generator
.Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_ALLOWED_FUTURE_MILLIS
Default value for
getAllowedFutureMillis() . |
static int |
DEFAULT_BITS_NODE_ID
Default value for
getBitsNodeId() . |
static int |
DEFAULT_BITS_SEQUENCE
Default value for
getBitsSequence() . |
static long |
DEFAULT_EPOCH_START
Default value for
getEpochStart() . |
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 and Description |
---|
FlakeIdGeneratorConfig() |
FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)
Copy-constructor
|
FlakeIdGeneratorConfig(String name) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(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.
|
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 |
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(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
|
public static final int DEFAULT_PREFETCH_COUNT
getPrefetchCount()
.public static final long DEFAULT_PREFETCH_VALIDITY_MILLIS
getPrefetchValidityMillis()
.public static final long DEFAULT_EPOCH_START
getEpochStart()
. 1514764800000
is the value System.currentTimeMillis()
would return on 1.1.2018 0:00 UTC.public static final int DEFAULT_BITS_SEQUENCE
getBitsSequence()
.public static final int DEFAULT_BITS_NODE_ID
getBitsNodeId()
.public static final long DEFAULT_ALLOWED_FUTURE_MILLIS
getAllowedFutureMillis()
.public static final int MAXIMUM_PREFETCH_COUNT
DEFAULT_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.
public FlakeIdGeneratorConfig()
public FlakeIdGeneratorConfig(String name)
public FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)
public String getName()
getName
in interface NamedConfig
public FlakeIdGeneratorConfig setName(String name)
Config
.setName
in interface NamedConfig
public int getPrefetchCount()
setPrefetchCount(int)
public FlakeIdGeneratorConfig setPrefetchCount(int prefetchCount)
FlakeIdGenerator.newId()
is made. Default is 100.
This setting pertains only to newId()
calls made on the member
that configured it.
prefetchCount
- the desired prefetch count, in the range 1..100000.public long getPrefetchValidityMillis()
setPrefetchValidityMillis(long)
public FlakeIdGeneratorConfig setPrefetchValidityMillis(long prefetchValidityMs)
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.
prefetchValidityMs
- the desired ID validity or unlimited, if <=0public FlakeIdGeneratorConfig setEpochStart(long epochStart)
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.
epochStart
- the desired epoch startpublic long getEpochStart()
setEpochStart(long)
public long getNodeIdOffset()
setNodeIdOffset(long)
public FlakeIdGeneratorConfig setNodeIdOffset(long nodeIdOffset)
nodeIdOffset
- the value added to the node idfor the node id logic
public int getBitsSequence()
setBitsSequence(int)
public FlakeIdGeneratorConfig setBitsSequence(int bitsSequence)
FlakeIdGenerator
's class javadoc for more
information.bitsSequence
- sequence component bit-lengthpublic int getBitsNodeId()
setBitsNodeId(int)
public FlakeIdGeneratorConfig setBitsNodeId(int bitsNodeId)
FlakeIdGenerator
's class javadoc for
more information.bitsNodeId
- node id component bit-lengthpublic long getAllowedFutureMillis()
setAllowedFutureMillis(long)
public FlakeIdGeneratorConfig setAllowedFutureMillis(long allowedFutureMillis)
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.
allowedFutureMillis
- value in millisecondspublic boolean isStatisticsEnabled()
setStatisticsEnabled(boolean)
public FlakeIdGeneratorConfig setStatisticsEnabled(boolean statisticsEnabled)
LocalFlakeIdGeneratorStats
.statisticsEnabled
- true
if statistics gathering is enabled
(which is also the default), false
otherwisepublic int getFactoryId()
IdentifiedDataSerializable
getFactoryId
in interface IdentifiedDataSerializable
public int getClassId()
IdentifiedDataSerializable
getClassId
in interface IdentifiedDataSerializable
public void writeData(ObjectDataOutput out) throws IOException
DataSerializable
writeData
in interface DataSerializable
out
- outputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.public void readData(ObjectDataInput in) throws IOException
DataSerializable
readData
in interface DataSerializable
in
- inputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
input stream has been closed.Copyright © 2020 Hazelcast, Inc.. All rights reserved.