public class DefaultUidGenerator extends Object implements UidGenerator, org.springframework.beans.factory.InitializingBean
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
| 构造器和说明 |
|---|
DefaultUidGenerator() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterPropertiesSet() |
long |
getUid()
Get a unique ID
|
protected long |
nextId()
Get UID
|
String |
parseUid(long uid)
Parse the UID into elements which are used to generate the UID.
|
void |
setEpochStr(String epochStr) |
void |
setSeqBits(int seqBits) |
void |
setTimeBits(int timeBits) |
void |
setWorkerBits(int workerBits) |
void |
setWorkerIdAssigner(WorkerIdAssigner workerIdAssigner)
Setters for spring property
|
public void afterPropertiesSet()
throws Exception
afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBeanExceptionpublic long getUid()
throws UidGenerateException
UidGeneratorgetUid 在接口中 UidGeneratorUidGenerateExceptionpublic String parseUid(long uid)
UidGeneratorparseUid 在接口中 UidGeneratorprotected long nextId()
UidGenerateException - in the case: Clock moved backwards; Exceeds the max timestamppublic void setWorkerIdAssigner(WorkerIdAssigner workerIdAssigner)
public void setTimeBits(int timeBits)
public void setWorkerBits(int workerBits)
public void setSeqBits(int seqBits)
public void setEpochStr(String epochStr)
Copyright © 2023. All rights reserved.