import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import java.util.Calendar;
/**
* Default distributed primary key generator.
*
*
* Use snowflake algorithm. Length is 64 bit.
*
*
*
* 1bit sign bit.
* 41bits timestamp offset from 2016.11.01(ShardingSphere distributed primary key published data) to now.
* 10bits worker process id.
* 12bits auto increment offset in one mills
*
*
*
* Call @{@code DefaultKeyGenerator.setWorkerId} to set worker id, default value is 0.
*
*
*
* Call @{@code DefaultKeyGenerator.setMaxTolerateTimeDifferenceMilliseconds} to set max tolerate time difference milliseconds, default value is 0.
*
*
* @author gaohongtao
*/
@Slf4j
public final class SnowflakeKeyGenerator {
public static final long EPOCH;
private static final long SEQUENCE_BITS = 12L;
private static final long WORKER_ID_BITS = 10L;
private static final long SEQUENCE_MASK = (1 << SEQUENCE_BITS) - 1;
private static final long WORKER_ID_LEFT_SHIFT_BITS &