public class DefaultUIdWorker extends Object implements UIdWorker
UIdWorker
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 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 |
构造器和说明 |
---|
DefaultUIdWorker(int timeBits,
int workerBits,
int seqBits,
String epochStr,
long workerId) |
protected int timeBits
protected int workerBits
protected int seqBits
protected String epochStr
protected long epochSeconds
protected BitsAllocator bitsAllocator
protected long workerId
protected long sequence
protected long lastSecond
public DefaultUIdWorker(int timeBits, int workerBits, int seqBits, String epochStr, long workerId)
public long getUID() throws IdGenerateException
UIdWorker
getUID
在接口中 UIdWorker
IdGenerateException
public String parseUID(long uid)
UIdWorker
protected long nextId()
IdGenerateException
- in the case: Clock moved backwards; Exceeds the max timestamp