Package com.bytedesk.core.uid.impl
Class BitsAllocator
java.lang.Object
com.bytedesk.core.uid.impl.BitsAllocator
Allocate 64 bits for the UID(long)
sign (fixed 1bit) -> deltaSecond -> workerId -> sequence(within the same second)
sign (fixed 1bit) -> deltaSecond -> workerId -> sequence(within the same second)
- Author:
- yutianbao
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final long
Max value for workId sequenceprivate final long
private final long
private final int
private int
Bits for [sign-> second-> workId-> sequence]private final int
private final int
Shift for timestamp workerIdstatic final int
Total 64 bitsprivate final int
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionBitsAllocator
(int timestampBits, int workerIdBits, int sequenceBits) Constructor with timestampBits, workerIdBits, sequenceBits
The highest bit used for sign, so63
bits for timestampBits, workerIdBits, sequenceBits -
Method Summary
Modifier and TypeMethodDescriptionlong
allocate
(long deltaSeconds, long workerId, long sequence) Allocate bits for UID according to delta seconds workerId sequence
Note that: The highest bit will always be 0 for sign
-
Field Details
-
TOTAL_BITS
public static final int TOTAL_BITSTotal 64 bits- See Also:
-
signBits
private int signBitsBits for [sign-> second-> workId-> sequence] -
timestampBits
private final int timestampBits -
workerIdBits
private final int workerIdBits -
sequenceBits
private final int sequenceBits -
maxDeltaSeconds
private final long maxDeltaSecondsMax value for workId sequence -
maxWorkerId
private final long maxWorkerId -
maxSequence
private final long maxSequence -
timestampShift
private final int timestampShiftShift for timestamp workerId -
workerIdShift
private final int workerIdShift
-
-
Constructor Details
-
BitsAllocator
public BitsAllocator(int timestampBits, int workerIdBits, int sequenceBits) Constructor with timestampBits, workerIdBits, sequenceBits
The highest bit used for sign, so63
bits for timestampBits, workerIdBits, sequenceBits
-
-
Method Details
-
allocate
public long allocate(long deltaSeconds, long workerId, long sequence) Allocate bits for UID according to delta seconds workerId sequence
Note that: The highest bit will always be 0 for sign- Parameters:
deltaSeconds
-workerId
-sequence
-- Returns:
-