using System.Threading;
namespace POSV.LoadBalance
{
///
/// RoundRobin Select
///
///
public class RoundRobinRouting : Routing
{
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];
}
}
}