|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.github.drinkjava2.jdialects.id.SnowflakeCreator
public class SnowflakeCreator
java edition of Twitter Snowflake, a network service for generating
unique ID numbers at high scale with some simple guarantees.
https://github.com/twitter/snowflake
Usage example: long id= new SnowflakeCreator(5L,5L, 18, 31).nextId();
P1 is datacenterIdBits, 1~9 bits
P2 is workerIdBits, 1~9 bits
P3 is real datacenterId, 0 to 511
P4 is real workerId, 0 to 511
Should: P1 + P2 = 10 (2^10=1024)
Should: P3 + P4 < 1024
| Constructor Summary | |
|---|---|
SnowflakeCreator(long datacenterIdBits,
long workerIdBits,
long datacenterId,
long workerId)
|
|
| Method Summary | |
|---|---|
String |
formatId(long id)
extract and display time stamp, datacenterId, workerId and sequence number information from the given id in humanization format |
long |
getEpoch()
|
long |
getWaitCount()
|
long |
nextId()
generate an unique and incrementing id |
long[] |
parseId(long id)
extract time stamp, datacenterId, workerId and sequence number information from the given id |
protected long |
timestampGen()
get current time stamp |
String |
toString()
show settings of Snowflake |
protected long |
waitNextMillis(long currTimestamp)
running loop blocking until next millisecond |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SnowflakeCreator(long datacenterIdBits,
long workerIdBits,
long datacenterId,
long workerId)
datacenterId - data center number the process running on, value range: [0,31]workerId - machine or process number, value range: [0,31]| Method Detail |
|---|
public long nextId()
public long getWaitCount()
waitNextMillis(long) methodprotected long waitNextMillis(long currTimestamp)
currTimestamp - current time stamp
protected long timestampGen()
public String toString()
toString in class Objectpublic long getEpoch()
public long[] parseId(long id)
id - a snowflake id generated by this object
public String formatId(long id)
id - snowflake id in Long format
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||