Package me.ahoo.cosid.snowflake
Class AbstractSnowflakeId
java.lang.Object
me.ahoo.cosid.snowflake.AbstractSnowflakeId
- All Implemented Interfaces:
IdGenerator
,SnowflakeId
,Statistical
,StringIdGenerator
- Direct Known Subclasses:
MillisecondSnowflakeId
,SecondSnowflakeId
Abstract SnowflakeId.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final long
protected long
protected final int
protected final long
WARN:machineLeft greater than 30 will cause overflow, so machineId should be long when calculating.protected final long
protected final int
protected final long
protected final long
protected long
protected final int
protected final int
protected final long
Fields inherited from interface me.ahoo.cosid.snowflake.SnowflakeId
TOTAL_BIT
-
Constructor Summary
ConstructorDescriptionAbstractSnowflakeId
(long epoch, int timestampBit, int machineBit, int sequenceBit, int machineId, long sequenceResetThreshold) -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface me.ahoo.cosid.IdGenerator
generateAsString, idConverter
Methods inherited from interface me.ahoo.cosid.snowflake.SnowflakeId
isSafeJavascript, stat
-
Field Details
-
epoch
protected final long epoch -
timestampBit
protected final int timestampBit -
machineBit
protected final int machineBit -
sequenceBit
protected final int sequenceBit -
maxTimestamp
protected final long maxTimestamp -
maxSequence
protected final long maxSequence -
maxMachineId
protected final int maxMachineId -
machineLeft
protected final long machineLeft -
timestampLeft
protected final long timestampLeft -
machineId
protected final long machineIdWARN:machineLeft greater than 30 will cause overflow, so machineId should be long when calculating. -
sequence
protected long sequence -
lastTimestamp
protected long lastTimestamp
-
-
Constructor Details
-
AbstractSnowflakeId
public AbstractSnowflakeId(long epoch, int timestampBit, int machineBit, int sequenceBit, int machineId, long sequenceResetThreshold)
-
-
Method Details
-
nextTime
protected long nextTime() -
getCurrentTime
protected abstract long getCurrentTime()get current timestamp.- Returns:
- current timestamp
-
generate
public long generate()Description copied from interface:IdGenerator
Generate distributed ID.- Specified by:
generate
in interfaceIdGenerator
- Returns:
- generated distributed ID
-
getEpoch
public long getEpoch()- Specified by:
getEpoch
in interfaceSnowflakeId
-
getTimestampBit
public int getTimestampBit()- Specified by:
getTimestampBit
in interfaceSnowflakeId
-
getMachineBit
public int getMachineBit()- Specified by:
getMachineBit
in interfaceSnowflakeId
-
getSequenceBit
public int getSequenceBit()- Specified by:
getSequenceBit
in interfaceSnowflakeId
-
getMaxTimestamp
public long getMaxTimestamp()- Specified by:
getMaxTimestamp
in interfaceSnowflakeId
-
getMaxMachineId
public int getMaxMachineId()- Specified by:
getMaxMachineId
in interfaceSnowflakeId
-
getMaxSequence
public long getMaxSequence()- Specified by:
getMaxSequence
in interfaceSnowflakeId
-
getLastTimestamp
public long getLastTimestamp()- Specified by:
getLastTimestamp
in interfaceSnowflakeId
-
getMachineId
public int getMachineId()- Specified by:
getMachineId
in interfaceSnowflakeId
-