public interface IdGenerator extends DistributedObject
long
IDs in a cluster.
In theory a IAtomicLong.incrementAndGet()
could be used to provide the same functionality.
The big difference is that the incrementAndGet requires one or more remote calls for every invocation and therefor
is a performance and scalability bottleneck. The IdGenerator uses an IAtomicLong under the hood, but instead of
doing remote call for every call to newId()
, it does it less frequently. It checks out a chunk, e.g. 1..1000 and
as long as it has not yet consumed all the IDs in its chunk, then no remote call is done.
It can be that IDs generated by different cluster members will get out of order because each member will get its own chunk.
It can be that member 1 has chunk 1..1000 and member 2 has 1001..2000. Therefore, member 2 will automatically have IDs that
are out of order with the IDs generated by member 1.Modifier and Type | Method and Description |
---|---|
boolean |
init(long id)
Tries to initialize this IdGenerator instance with the given ID.
|
long |
newId()
Generates and returns a cluster-wide unique ID.
|
destroy, getName, getPartitionKey, getServiceName
boolean init(long id)
The first generated ID will be 1 greater than ID.
true
if initialization succeeded, false
if ID is less than 0.long newId()
Generated IDs are guaranteed to be unique for the entire cluster as long as the cluster is live. If the cluster restarts, then ID generation will start from 0.
Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.