示例#1
0
        public SnowWorkerM1(IdGeneratorOptions options)
        {
            // 1.BaseTime
            if (options.BaseTime != DateTime.MinValue)
            {
                BaseTime = options.BaseTime;
            }

            // 2.WorkerIdBitLength
            if (options.WorkerIdBitLength == 0)
            {
                WorkerIdBitLength = 6;
            }
            else
            {
                WorkerIdBitLength = options.WorkerIdBitLength;
            }

            // 3.WorkerId
            WorkerId = options.WorkerId;

            // 4.SeqBitLength
            if (options.SeqBitLength == 0)
            {
                SeqBitLength = 6;
            }
            else
            {
                SeqBitLength = options.SeqBitLength;
            }

            // 5.MaxSeqNumber
            if (MaxSeqNumber == 0)
            {
                MaxSeqNumber = (1 << SeqBitLength) - 1;
            }
            else
            {
                MaxSeqNumber = options.MaxSeqNumber;
            }

            // 6.MinSeqNumber
            MinSeqNumber = options.MinSeqNumber;

            // 7.Others
            TopOverCostCount = options.TopOverCostCount;
            if (TopOverCostCount == 0)
            {
                TopOverCostCount = 2000;
            }

            _TimestampShift   = (byte)(WorkerIdBitLength + SeqBitLength);
            _CurrentSeqNumber = options.MinSeqNumber;

            //_BaseTimeTick = BaseTime.Ticks;
            //_StartTimeTick = (long)(DateTime.UtcNow.Subtract(BaseTime).TotalMilliseconds) - Environment.TickCount;
        }
示例#2
0
        public SnowWorkerM3(IdGeneratorOptions options) : base(options)
        {
            // 秒级时间戳类型
            TimestampType = options.TimestampType;

            // DataCenter相关
            DataCenterId          = options.DataCenterId;
            DataCenterIdBitLength = options.DataCenterIdBitLength;

            if (TimestampType == 1)
            {
                TopOverCostCount = 0;
            }
            _TimestampShift = (byte)(DataCenterIdBitLength + WorkerIdBitLength + SeqBitLength);
        }
示例#3
0
        public SnowWorkerM1(IdGeneratorOptions options)
        {
            WorkerId          = options.WorkerId;
            WorkerIdBitLength = options.WorkerIdBitLength;
            SeqBitLength      = options.SeqBitLength;
            MaxSeqNumber      = options.MaxSeqNumber;
            MinSeqNumber      = options.MinSeqNumber;
            TopOverCostCount  = options.TopOverCostCount;

            if (options.BaseTime != DateTime.MinValue)
            {
                BaseTime = options.BaseTime;
            }

            if (WorkerId < 1)
            {
                WorkerId = (ushort)DateTime.Now.Millisecond;
            }

            if (SeqBitLength == 0)
            {
                SeqBitLength = 6;
            }

            if (WorkerIdBitLength == 0)
            {
                WorkerIdBitLength = 6;
            }

            if (MaxSeqNumber == 0)
            {
                MaxSeqNumber = (1 << SeqBitLength) - 1;
            }

            _TimestampShift   = (byte)(WorkerIdBitLength + SeqBitLength);
            _CurrentSeqNumber = options.MinSeqNumber;

            //_BaseTimeTick = BaseTime.Ticks;
            //_StartTimeTick = (long)(DateTime.UtcNow.Subtract(BaseTime).TotalMilliseconds) - Environment.TickCount;
        }
示例#4
0
 /// <summary>
 /// 设置参数,建议程序初始化时执行一次
 /// </summary>
 /// <param name="options"></param>
 public static void SetIdGenerator(IdGeneratorOptions options)
 {
     _IdGenInstance = new DefaultIdGenerator(options);
 }
示例#5
0
 public SnowWorkerM2(IdGeneratorOptions options) : base(options)
 {
 }