Example #1
0
        public virtual Server Choose(LoadBalancerRoute route)
        {
            if (route == null || route.ServerGroups.IsNullOrEmpty())
            {
                return(null);
            }

            InternalBuildLoadBalanceItems(route);
            ServerGroup serverGroup = null;

            for (int i = 0; i < serverGroups.Count; i++)
            {
                serverGroup = roundRobinAlgorithm.Choose(serverGroups);
                if (serverGroup.AvailableServers.Length > 0)
                {
                    break;
                }
            }
            if (serverGroup == null)
            {
                return(null);
            }

            var serverContext = serverContexts.GetOrAdd(serverGroup.GroupId, key => new RoundRobinContext(serverGroup));

            return(serverContext.Choose());
        }
 public Server Choose()
 {
     return(roundRobinAlgorithm.Choose(ServerGroup.AvailableServers));
 }