mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Consul;
|
|
using Microsoft.Extensions.Options;
|
|
using Yi.Framework.Common.IOCOptions;
|
|
|
|
namespace Yi.Framework.Core.ConsulExtend
|
|
{
|
|
/// <summary>
|
|
/// 平均
|
|
/// </summary>
|
|
public class AverageDispatcher : AbstractConsulDispatcher
|
|
{
|
|
#region Identity
|
|
private static int _iTotalCount = 0;
|
|
private static int iTotalCount
|
|
{
|
|
get
|
|
{
|
|
return _iTotalCount;
|
|
}
|
|
set
|
|
{
|
|
_iTotalCount = value >= Int32.MaxValue ? 0 : value;
|
|
}
|
|
}
|
|
|
|
|
|
public AverageDispatcher(IOptionsMonitor<ConsulClientOption> consulClientOption) : base(consulClientOption)
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 平均
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected override int GetIndex()
|
|
{
|
|
return new Random(iTotalCount++).Next(0, base._CurrentAgentServiceDictionary.Length);
|
|
}
|
|
}
|
|
}
|