auto commit
This commit is contained in:
29
C#/source/Yitter.IdGenerator/Contract/IIdGenerator.cs
Normal file
29
C#/source/Yitter.IdGenerator/Contract/IIdGenerator.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 版权属于:yitter(yitter@126.com)
|
||||
* 开源地址:https://github.com/yitter/idgenerator
|
||||
* 版权协议:MIT
|
||||
* 版权说明:只要保留本版权,你可以免费使用、修改、分发本代码。
|
||||
* 免责条款:任何因为本代码产生的系统、法律、政治、宗教问题,均与版权所有者无关。
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Yitter.IdGenerator
|
||||
{
|
||||
public interface IIdGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成过程中产生的事件
|
||||
/// </summary>
|
||||
//Action<OverCostActionArg> GenIdActionAsync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生成新的long型Id
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
long NewLong();
|
||||
|
||||
// Guid NewGuid();
|
||||
}
|
||||
}
|
||||
22
C#/source/Yitter.IdGenerator/Contract/ISnowWorker.cs
Normal file
22
C#/source/Yitter.IdGenerator/Contract/ISnowWorker.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 版权属于:yitter(yitter@126.com)
|
||||
* 开源地址:https://github.com/yitter/idgenerator
|
||||
* 版权协议:MIT
|
||||
* 版权说明:只要保留本版权,你可以免费使用、修改、分发本代码。
|
||||
* 免责条款:任何因为本代码产生的系统、法律、政治、宗教问题,均与版权所有者无关。
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Yitter.IdGenerator
|
||||
{
|
||||
internal interface ISnowWorker
|
||||
{
|
||||
//Action<OverCostActionArg> GenAction { get; set; }
|
||||
|
||||
long NextId();
|
||||
}
|
||||
}
|
||||
92
C#/source/Yitter.IdGenerator/Contract/IdGeneratorOptions.cs
Normal file
92
C#/source/Yitter.IdGenerator/Contract/IdGeneratorOptions.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 版权属于:yitter(yitter@126.com)
|
||||
* 开源地址:https://github.com/yitter/idgenerator
|
||||
* 版权协议:MIT
|
||||
* 版权说明:只要保留本版权,你可以免费使用、修改、分发本代码。
|
||||
* 免责条款:任何因为本代码产生的系统、法律、政治、宗教问题,均与版权所有者无关。
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Yitter.IdGenerator
|
||||
{
|
||||
public class IdGeneratorOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 雪花计算方法
|
||||
/// (1-漂移算法|2-传统算法),默认1
|
||||
/// </summary>
|
||||
public virtual short Method { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 基础时间(UTC格式)
|
||||
/// 不能超过当前系统时间
|
||||
/// </summary>
|
||||
public virtual DateTime BaseTime { get; set; } = new DateTime(2020, 2, 20, 2, 20, 2, 20, DateTimeKind.Utc);
|
||||
|
||||
/// <summary>
|
||||
/// 机器码
|
||||
/// 必须由外部设定,最大值 2^WorkerIdBitLength-1
|
||||
/// </summary>
|
||||
public virtual ushort WorkerId { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 机器码位长
|
||||
/// 默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22)
|
||||
/// </summary>
|
||||
public virtual byte WorkerIdBitLength { get; set; } = 6;//10;
|
||||
|
||||
/// <summary>
|
||||
/// 序列数位长
|
||||
/// 默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22)
|
||||
/// </summary>
|
||||
public virtual byte SeqBitLength { get; set; } = 6;//10;
|
||||
|
||||
/// <summary>
|
||||
/// 最大序列数(含)
|
||||
/// 设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1])
|
||||
/// </summary>
|
||||
public virtual int MaxSeqNumber { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 最小序列数(含)
|
||||
/// 默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位
|
||||
/// </summary>
|
||||
public virtual ushort MinSeqNumber { get; set; } = 5;
|
||||
|
||||
/// <summary>
|
||||
/// 最大漂移次数(含),
|
||||
/// 默认2000,推荐范围500-10000(与计算能力有关)
|
||||
/// </summary>
|
||||
public virtual int TopOverCostCount { get; set; } = 2000;
|
||||
|
||||
/// <summary>
|
||||
/// 数据中心ID(默认0)
|
||||
/// </summary>
|
||||
public virtual uint DataCenterId { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 数据中心ID长度(默认0)
|
||||
/// </summary>
|
||||
public virtual byte DataCenterIdBitLength { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 时间戳类型(0-毫秒,1-秒),默认0
|
||||
/// </summary>
|
||||
public virtual byte TimestampType { get; set; } = 0;
|
||||
|
||||
|
||||
public IdGeneratorOptions()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public IdGeneratorOptions(ushort workerId)
|
||||
{
|
||||
WorkerId = workerId;
|
||||
}
|
||||
}
|
||||
}
|
||||
57
C#/source/Yitter.IdGenerator/Contract/OverCostActionArg.cs
Normal file
57
C#/source/Yitter.IdGenerator/Contract/OverCostActionArg.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 版权属于:yitter(yitter@126.com)
|
||||
* 开源地址:https://github.com/yitter/idgenerator
|
||||
* 版权协议:MIT
|
||||
* 版权说明:只要保留本版权,你可以免费使用、修改、分发本代码。
|
||||
* 免责条款:任何因为本代码产生的系统、法律、政治、宗教问题,均与版权所有者无关。
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Yitter.IdGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Id生成时回调参数
|
||||
/// </summary>
|
||||
public class OverCostActionArg
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件类型
|
||||
/// 1-开始,2-结束,8-漂移
|
||||
/// </summary>
|
||||
public virtual int ActionType { get; set; }
|
||||
/// <summary>
|
||||
/// 时间戳
|
||||
/// </summary>
|
||||
public virtual long TimeTick { get; set; }
|
||||
/// <summary>
|
||||
/// 机器码
|
||||
/// </summary>
|
||||
public virtual ushort WorkerId { get; set; }
|
||||
/// <summary>
|
||||
/// 漂移计算次数
|
||||
/// </summary>
|
||||
public virtual int OverCostCountInOneTerm { get; set; }
|
||||
/// <summary>
|
||||
/// 漂移期间生产ID个数
|
||||
/// </summary>
|
||||
public virtual int GenCountInOneTerm { get; set; }
|
||||
/// <summary>
|
||||
/// 漂移周期
|
||||
/// </summary>
|
||||
public virtual int TermIndex { get; set; }
|
||||
|
||||
public OverCostActionArg(ushort workerId, long timeTick, int actionType = 0, int overCostCountInOneTerm = 0, int genCountWhenOverCost = 0, int index = 0)
|
||||
{
|
||||
ActionType = actionType;
|
||||
TimeTick = timeTick;
|
||||
WorkerId = workerId;
|
||||
OverCostCountInOneTerm = overCostCountInOneTerm;
|
||||
GenCountInOneTerm = genCountWhenOverCost;
|
||||
TermIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user