You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
665 B
C#
29 lines
665 B
C#
using System.Threading;
|
|
|
|
namespace AutoUpdater
|
|
{
|
|
/// <summary>
|
|
/// RoundRobin Select
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class RoundRobinRouting<T> : Routing<T>
|
|
{
|
|
private int _next;
|
|
|
|
public RoundRobinRouting()
|
|
: this(-1)
|
|
{ }
|
|
|
|
public RoundRobinRouting(int next)
|
|
{
|
|
_next = next;
|
|
}
|
|
|
|
protected override T selectInternal(object message, T[] instances)
|
|
{
|
|
var roundNext = Interlocked.Increment(ref _next) & int.MaxValue;
|
|
return instances[roundNext % instances.Length];
|
|
}
|
|
}
|
|
}
|