Class IdGenerator.Snowflake
- java.lang.Object
-
- cn.fantasticmao.mundo.data.support.IdGenerator.Snowflake
-
- All Implemented Interfaces:
IdGenerator
- Enclosing interface:
- IdGenerator
public static class IdGenerator.Snowflake extends Object implements IdGenerator
Twitter Snowflake- See Also:
- Announcing Snowflake, twitter-archive snowflake
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cn.fantasticmao.mundo.data.support.IdGenerator
IdGenerator.Snowflake
-
-
Field Summary
Fields Modifier and Type Field Description protected static intLEFT_SEQUENCE_NUMBERprotected static intLEFT_TIMESTAMPprotected static intLEFT_WORKER_NUMBERprotected static longMAX_SEQUENCE_NUMBERprotected static longMAX_TIMESTAMPprotected static longMAX_WORKER_NUMBER
-
Constructor Summary
Constructors Modifier Constructor Description protectedSnowflake(long workerNumber)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static longgetSequence(long id)protected static longgetTimestamp(long id)protected static longgetWorkerNumber(long id)static IdGeneratornewInstance(long workerNumber)longnext()protected longtimeGen()
-
-
-
Field Detail
-
LEFT_SEQUENCE_NUMBER
protected static final int LEFT_SEQUENCE_NUMBER
- See Also:
- Constant Field Values
-
LEFT_WORKER_NUMBER
protected static final int LEFT_WORKER_NUMBER
- See Also:
- Constant Field Values
-
LEFT_TIMESTAMP
protected static final int LEFT_TIMESTAMP
- See Also:
- Constant Field Values
-
MAX_TIMESTAMP
protected static final long MAX_TIMESTAMP
- See Also:
- Constant Field Values
-
MAX_WORKER_NUMBER
protected static final long MAX_WORKER_NUMBER
- See Also:
- Constant Field Values
-
MAX_SEQUENCE_NUMBER
protected static final long MAX_SEQUENCE_NUMBER
- See Also:
- Constant Field Values
-
-
Method Detail
-
newInstance
public static IdGenerator newInstance(long workerNumber)
-
getTimestamp
protected static long getTimestamp(long id)
-
getWorkerNumber
protected static long getWorkerNumber(long id)
-
getSequence
protected static long getSequence(long id)
-
next
public long next()
- Specified by:
nextin interfaceIdGenerator
-
timeGen
protected long timeGen()
-
-