类 SnowFlake
java.lang.Object
cn.vorbote.core.utils.SnowFlake
Distributed Sequence Generator.
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected longawaitToNextMillis(long lastTimestamp) Block until the next millisecond until a new timestamp is obtained.protected longReturn current timestamp with the unit of millisecond.longnextId()Get next unique id.
-
构造器详细资料
-
SnowFlake
public SnowFlake(long workerId, long dataCentreId) Constructor can build a new SnowFlake instance.- 参数:
workerId- The id of the server. (Should between 0 and 31)dataCentreId- The id of the data centre. (Should between 0 and 31)
-
SnowFlake
public SnowFlake(long startEpoch, long workerId, long dataCentreId) Constructor can build a new SnowFlake instance.- 参数:
startEpoch- The start epoch to calculate.workerId- The id of the server. (Should between 0 and 31)dataCentreId- The id of the data centre. (Should between 0 and 31)
-
-
方法详细资料
-
nextId
public long nextId()Get next unique id.- 返回:
- A unique id.
-
awaitToNextMillis
protected long awaitToNextMillis(long lastTimestamp) Block until the next millisecond until a new timestamp is obtained.- 参数:
lastTimestamp- The timestamp when id was created last time.- 返回:
- Current timestamp.
-
currentTimestamp
protected long currentTimestamp()Return current timestamp with the unit of millisecond.- 返回:
- Current time.
-