コード例 #1
0
        public SemaphoreIsolation(string instanceKey, string commandKey, string groupKey, string domain, Action <ICommandConfigSet> config)
        {
            Func <string, CommandComponents>  valueFactory = null;
            Func <string, IsolationSemaphore> func2        = null;

            if (string.IsNullOrWhiteSpace(commandKey))
            {
                string message = "HystrixCommand Key cannot be null.";
                CommonUtils.Log.Log(LogLevelEnum.Fatal, message, new Dictionary <string, string>().AddLogTagData("FXD303002"));
                throw new ArgumentNullException(message);
            }
            this.Key    = CommonUtils.GenerateKey(instanceKey, commandKey);
            instanceKey = string.IsNullOrWhiteSpace(instanceKey) ? null : instanceKey.Trim();
            commandKey  = commandKey.Trim();
            groupKey    = groupKey ?? "DefaultGroup";
            domain      = domain ?? "Ant";
            if (valueFactory == null)
            {
                valueFactory = key => HystrixCommandBase.CreateCommandComponents(this.Key, instanceKey, commandKey, groupKey, domain, IsolationModeEnum.SemaphoreIsolation, config, typeof(SemaphoreIsolation));
            }
            this.Components = HystrixCommandBase.CommandComponentsCollection.GetOrAdd(this.Key, valueFactory);
            if (func2 == null)
            {
                func2 = key => new IsolationSemaphore(this.Components.ConfigSet.CommandMaxConcurrentCount);
            }
            this.ExecutionSemaphore = HystrixCommandBase.ExecutionSemaphores.GetOrAdd(this.Key, func2);
            this._stopwatch         = new Stopwatch();
        }
コード例 #2
0
        public SemaphoreIsolation(string instanceKey, string commandKey, string groupKey, string domain, Action <ICommandConfigSet> config)
        {
            if (string.IsNullOrWhiteSpace(commandKey))
            {
                string message = "HystrixCommand Key cannot be null.";
                CommonUtils.Log.Log(LogLevelEnum.Fatal, message, new Dictionary <string, string>().AddLogTagData("FXD303002"));
                throw new ArgumentNullException(message);
            }

            Key         = CommonUtils.GenerateKey(instanceKey, commandKey);
            instanceKey = string.IsNullOrWhiteSpace(instanceKey) ? null : instanceKey.Trim();
            commandKey  = commandKey.Trim();
            groupKey    = groupKey ?? HystrixCommandBase.DefaultGroupKey;
            domain      = domain ?? CommandDomains.Default;

            Components = HystrixCommandBase.CommandComponentsCollection.GetOrAdd(Key, key =>
                                                                                 HystrixCommandBase.CreateCommandComponents(Key, instanceKey,
                                                                                                                            commandKey, groupKey, domain, IsolationModeEnum.SemaphoreIsolation, config, typeof(SemaphoreIsolation)));
            ExecutionSemaphore = HystrixCommandBase.ExecutionSemaphores.GetOrAdd(Key,
                                                                                 key => new IsolationSemaphore(Components.ConfigSet.CommandMaxConcurrentCount));

            _stopwatch = new Stopwatch();
        }