public class DefaultUidGenerator
extends java.lang.Object
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() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterPropertiesSet()
Spring property
|
long |
getUID() |
protected long |
nextId()
Get UID
|
java.lang.String |
parseUID(long 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 void afterPropertiesSet()
public long getUID()
throws CustomException
CustomExceptionpublic java.lang.String parseUID(long uid)
protected long nextId()
CustomException - 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)