public class DefaultUidGenerator extends java.lang.Object implements UidGenerator
UidGenerator
The unique id has 64bits (long), default allocated as blow:
The parseUID(long) is a tool method to parse the bits
+------+----------------------+----------------+-----------+
| sign | delta seconds | worker node id | sequence |
+------+----------------------+----------------+-----------+
1bit 28bits 22bits 13bits
You can also specified the bits by Spring property setting.
Note that: The total bits must be 64 -1
| 限定符和类型 | 字段和说明 |
|---|---|
protected BitsAllocator |
bitsAllocator
Stable fields after spring bean initializing
|
protected long |
epochSeconds |
protected java.lang.String |
epochStr
Customer epoch, unit as second.
|
protected long |
lastSecond |
protected int |
seqBits |
protected long |
sequence
Volatile fields caused by nextId()
|
protected int |
timeBits
Bits allocate
|
protected int |
workerBits |
protected long |
workerId |
| 构造器和说明 |
|---|
DefaultUidGenerator(long workerId) |
| 限定符和类型 | 方法和说明 |
|---|---|
long |
getUID()
Get a unique ID
|
protected long |
nextId()
Get UID
|
java.lang.String |
parseUID(long uid)
Parse the UID into elements which are used to generate the UID.
|
void |
setEpochStr(java.lang.String epochStr) |
void |
setSeqBits(int seqBits) |
void |
setTimeBits(int timeBits) |
void |
setWorkerBits(int workerBits) |
protected int timeBits
protected int workerBits
protected int seqBits
protected java.lang.String epochStr
protected long epochSeconds
protected BitsAllocator bitsAllocator
protected long workerId
protected long sequence
protected long lastSecond
public long getUID()
throws UidGenerateException
UidGeneratorgetUID 在接口中 UidGeneratorUidGenerateExceptionpublic java.lang.String parseUID(long uid)
UidGeneratorparseUID 在接口中 UidGeneratorprotected long nextId()
UidGenerateException - in the case: Clock moved backwards; Exceeds the max timestamppublic void setTimeBits(int timeBits)
public void setWorkerBits(int workerBits)
public void setSeqBits(int seqBits)
public void setEpochStr(java.lang.String epochStr)