예제 #1
0
        async Task UpdateServingNodes(IPEndPoint from, IPEndPoint servingNodeEndpoint)
        {
            var existingServingNodeEndPoints =
                from node in _servingNodes.GetControllers()
                where node.ServingEndPoint != servingNodeEndpoint
                select node.ServingEndPoint;

            //inform that serving node of all existing serving nodes
            await TaskCordinator.Retry(() => _loadBalancerProtocol.SendServingNodes(existingServingNodeEndPoints, from));

            //inform existing serving nodes of the new node
            var existingControlNodeEndPoints =
                from node in _servingNodes.GetControllers()
                where node.ServingEndPoint != servingNodeEndpoint
                select node.ControlEndPoint;
            var existingCallControllers =
                from controller in _callControllers.Controllers
                select controller.LoadBalancerEndPoint;

            foreach (var endPoint in existingControlNodeEndPoints.Concat(existingCallControllers))
            {
                TaskCordinator.DontWait(() => TaskCordinator.Retry(() => _loadBalancerProtocol.SendServingNodes(new IPEndPoint[] { servingNodeEndpoint }, endPoint)));
            }

            await InformServingNodeOfGroupCallControllers(from);
        }
예제 #2
0
        async Task RemoveExpiredControllers()
        {
            while (!_closing)
            {
                await Task.Delay(5000); //todo: find the time till the next controller expires and wait that long

                _servingNodes.RemoveExpired(removedNode =>
                {
                    var servingNodeEndpoint          = removedNode.ServingEndPoint;
                    var existingServingNodeEndPoints =
                        from node in _servingNodes.GetControllers()
                        select node.ControlEndPoint;
                    var callContollerEndPoints =
                        from node in _callControllers.Controllers
                        select node.LoadBalancerEndPoint;
                    foreach (var endPoint in existingServingNodeEndPoints.Concat(callContollerEndPoints))
                    {
                        Console.WriteLine($"Sending ServingNodeRemoved to {endPoint}");
                        TaskCordinator.DontWait(() => TaskCordinator.Retry(() => _loadBalancerProtocol.SendServingNodeRemoved(servingNodeEndpoint, endPoint)));
                    }
                });
                _callControllers.RemoveExpired();
            }
        }