public class FlakeIdGeneratorConfig extends Object implements IdentifiedDataSerializable
FlakeIdGeneratorConfig
contains the configuration for the member
regarding Flake ID Generator
.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 and Description |
---|
FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)
Copy-constructor
|
FlakeIdGeneratorConfig(String name) |
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
|
public static final int DEFAULT_PREFETCH_COUNT
getPrefetchCount()
.public static final long DEFAULT_PREFETCH_VALIDITY_MILLIS
getPrefetchValidityMillis()
.public static final int MAXIMUM_PREFETCH_COUNT
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.
public FlakeIdGeneratorConfig(String name)
public FlakeIdGeneratorConfig(FlakeIdGeneratorConfig other)
public FlakeIdGeneratorConfigReadOnly getAsReadOnly()
public String getName()
public void setName(String name)
Config
.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..100,000.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 long getIdOffset()
setIdOffset(long)
public FlakeIdGeneratorConfig setIdOffset(long idOffset)
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.
idOffset
- the value added to each generated IDpublic long getNodeIdOffset()
setNodeIdOffset(long)
public FlakeIdGeneratorConfig setNodeIdOffset(long nodeIdOffset)
nodeIdOffset
- the value added to the node idfor the node id logic
public 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 getId()
IdentifiedDataSerializable
getId
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 © 2022 Hazelcast, Inc.. All Rights Reserved.