public void SetClusterConfiguration(ClusterConfiguration configuration)
        {
            ClusterConfiguration = configuration;

            if (configuration != null)
            {
                multiplexer.Trace("Updating cluster ranges...");
                multiplexer.UpdateClusterRange(configuration);
                multiplexer.Trace("Resolving genealogy...");
                var thisNode = configuration.Nodes.FirstOrDefault(x => x.EndPoint == this.EndPoint);
                if (thisNode != null)
                {
                    List <ServerEndPoint> slaves = null;
                    ServerEndPoint        master = null;
                    foreach (var node in configuration.Nodes)
                    {
                        if (node.NodeId == thisNode.ParentNodeId)
                        {
                            master = multiplexer.GetServerEndPoint(node.EndPoint);
                        }
                        else if (node.ParentNodeId == thisNode.NodeId)
                        {
                            if (slaves == null)
                            {
                                slaves = new List <ServerEndPoint>();
                            }
                            slaves.Add(multiplexer.GetServerEndPoint(node.EndPoint));
                        }
                    }
                    Master = master;
                    Slaves = slaves?.ToArray() ?? NoSlaves;
                }
                multiplexer.Trace("Cluster configured");
            }
        }
Пример #2
0
        public void SetClusterConfiguration(ClusterConfiguration configuration)
        {
            ClusterConfiguration = configuration;

            if (configuration != null)
            {
                Multiplexer.Trace("Updating cluster ranges...");
                Multiplexer.UpdateClusterRange(configuration);
                Multiplexer.Trace("Resolving genealogy...");
                var thisNode = configuration.Nodes.FirstOrDefault(x => x.EndPoint.Equals(EndPoint));
                if (thisNode != null)
                {
                    List <ServerEndPoint> replicas = null;
                    ServerEndPoint        master   = null;
                    foreach (var node in configuration.Nodes)
                    {
                        if (node.NodeId == thisNode.ParentNodeId)
                        {
                            master = Multiplexer.GetServerEndPoint(node.EndPoint);
                        }
                        else if (node.ParentNodeId == thisNode.NodeId)
                        {
                            (replicas ?? (replicas = new List <ServerEndPoint>())).Add(Multiplexer.GetServerEndPoint(node.EndPoint));
                        }
                    }
                    Master   = master;
                    Replicas = replicas?.ToArray() ?? Array.Empty <ServerEndPoint>();
                }
                Multiplexer.Trace("Cluster configured");
            }
        }