Ejemplo n.º 1
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();
        }