Example #1
0
        internal ClientCluster(ClientClusterConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("传入的集群配置为空!");
            }
            if (string.IsNullOrEmpty(config.Name))
            {
                throw new ArgumentException("集群名为空!");
            }

            this.config = config;

            tryRecoverNodeThread = new Thread(TryRecoverNodeThreadAction)
            {
                Name         = string.Format("{0}_{1}", "Adhesive.DistributedComponentClient_TryRecoverNodeThread", config.Name),
                IsBackground = true,
            };
            tryRecoverNodeThread.Start();

            foreach (var nodeConfig in config.ClientNodeConfigurations.Select(item => item.Value).ToList())
            {
                if (clientNodes.ContainsKey(nodeConfig.Name))
                {
                    throw new Exception(string.Format("在集群 {0} 中已经存在名为 {1} 的节点!", config.Name, nodeConfig.Name));
                }
                var node = new ClientNode(nodeConfig, this.NodeError);
                locker.EnterWriteLock();
                try
                {
                    clientNodes.Add(nodeConfig.Name, node);
                }
                finally
                {
                    locker.ExitWriteLock();
                }
            }

            InitNodeLocator();
        }
Example #2
0
        internal ClientCluster(ClientClusterConfiguration config)
        {
            if (config == null)
                throw new ArgumentNullException("传入的集群配置为空!");
            if (string.IsNullOrEmpty(config.Name))
                throw new ArgumentException("集群名为空!");

            this.config = config;

            tryRecoverNodeThread = new Thread(TryRecoverNodeThreadAction)
            {
                Name = string.Format("{0}_{1}", "Adhesive.DistributedComponentClient_TryRecoverNodeThread", config.Name),
                IsBackground = true,
            };
            tryRecoverNodeThread.Start();

            foreach (var nodeConfig in config.ClientNodeConfigurations.Select(item => item.Value).ToList())
            {
                if (clientNodes.ContainsKey(nodeConfig.Name))
                    throw new Exception(string.Format("在集群 {0} 中已经存在名为 {1} 的节点!", config.Name, nodeConfig.Name));
                var node = new ClientNode(nodeConfig, this.NodeError);
                locker.EnterWriteLock();
                try
                {
                    clientNodes.Add(nodeConfig.Name, node);
                }
                finally
                {
                    locker.ExitWriteLock();
                }
            }

            InitNodeLocator();

        }