コード例 #1
0
ファイル: ZookeeperCluster.cs プロジェクト: Bart-Li/Base
        public static ZookeeperConfig GetZookeeperConfig()
        {
            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (!string.IsNullOrWhiteSpace(env) && Clusters.ContainsKey(env))
            {
                return(Clusters[env]);
            }

            return(Clusters["GDEV"]);
        }
コード例 #2
0
        /// <summary>
        /// 获取集群执行器
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        private ICluster GetCluster(IInvocation invocation)
        {
            var result = Clusters[FailoverCluster.NAME];

            var key = this.Address.GetMethodParameter(invocation.MethodInfo.Name, CLUSTER_KEY, "");

            if (string.IsNullOrEmpty(key) || key == FailoverCluster.NAME)
            {
                key = this.Address.GetInterfaceParameter(invocation.TargetType.FullName, CLUSTER_KEY, "");
            }
            if (Clusters.ContainsKey(key) && key != FailoverCluster.NAME)
            {
                result = Clusters[key];
            }

            //result.Pool = GetClientPool(invocation);
            //result.Address = this.Address;
            return(result);
        }
コード例 #3
0
        public Cluster this[string clusterName]
        {
            get
            {
                if (!Clusters.ContainsKey(clusterName))
                {
                    throw new ArgumentException();
                }

                return(Clusters[clusterName]);
            }
            set
            {
                if (!Clusters.ContainsKey(clusterName))
                {
                    throw new ArgumentException();
                }

                Clusters[clusterName] = value;
            }
        }
コード例 #4
0
        /// <summary>
        /// 获取集群执行器
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        private ICluster GetCluster(IInvocation invocation)
        {
            var result = Clusters[FailoverCluster.NAME];

            var key = this.Address.GetMethodParameter($"{invocation.TargetType.FullName}.{ invocation.MethodInfo.Name }", CLUSTER_KEY, "");

            if (string.IsNullOrEmpty(key))
            {
                key = this.Address.GetInterfaceParameter(invocation.TargetType.FullName, CLUSTER_KEY, "");
            }
            if (string.IsNullOrEmpty(key))
            {
                key = this.Address.GetParameter(CLUSTER_KEY, "");
            }
            if (!string.IsNullOrEmpty(key) && Clusters.ContainsKey(key) && key != FailoverCluster.NAME)
            {
                result = Clusters[key];
            }

            return(result);
        }