public IHystrixCommand GetHystrixCommand(HystrixCommandIdentifier commandIdentifier)
        {
            IHystrixCommand hystrixCommand;

            if (CommandsDictionary.TryGetValue(commandIdentifier, out hystrixCommand))
            {
                return(hystrixCommand);
            }

            // add value in a thread-safe way
            hystrixCommand = CommandsDictionary.AddOrUpdate(
                commandIdentifier,
                ci =>
            {
                Log.DebugFormat("Added a new command with group {0} and key {1}.", ci.GroupKey, ci.CommandKey);
                return(CreateHystrixCommand(ci));
            },
                (ci, command) =>
            {
                Log.DebugFormat("Command with group {0} and key {1} already exists, not creating it again.", ci.GroupKey, ci.CommandKey);
                return(command);
            });

            return(hystrixCommand);
        }
Пример #2
0
        public HystrixCommand(HystrixCommandIdentifier commandIdentifier, IHystrixTimeoutWrapper timeoutWrapper, IHystrixCircuitBreaker circuitBreaker, IHystrixCommandMetrics commandMetrics, IHystrixThreadPoolMetrics threadPoolMetrics, IHystrixConfigurationService configurationService)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException("commandIdentifier");
            }
            if (timeoutWrapper == null)
            {
                throw new ArgumentNullException("timeoutWrapper");
            }
            if (circuitBreaker == null)
            {
                throw new ArgumentNullException("circuitBreaker");
            }
            if (commandMetrics == null)
            {
                throw new ArgumentNullException("commandMetrics");
            }
            if (threadPoolMetrics == null)
            {
                throw new ArgumentNullException("threadPoolMetrics");
            }
            if (configurationService == null)
            {
                throw new ArgumentNullException("configurationService");
            }

            this.commandIdentifier    = commandIdentifier;
            this.timeoutWrapper       = timeoutWrapper;
            this.circuitBreaker       = circuitBreaker;
            this.commandMetrics       = commandMetrics;
            this.threadPoolMetrics    = threadPoolMetrics;
            this.configurationService = configurationService;
        }
Пример #3
0
 public HystrixCircuitBreaker(IDateTimeProvider dateTimeProvider, HystrixCommandIdentifier commandIdentifier, IHystrixConfigurationService configurationService, IHystrixCommandMetrics commandMetrics)
 {
     this.dateTimeProvider     = dateTimeProvider ?? throw new ArgumentNullException(nameof(dateTimeProvider));
     this.commandIdentifier    = commandIdentifier ?? throw new ArgumentNullException(nameof(commandIdentifier));
     this.configurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService));
     this.commandMetrics       = commandMetrics ?? throw new ArgumentNullException(nameof(commandMetrics));
 }
Пример #4
0
        public HystrixWebConfigConfigurationService(HystrixCommandIdentifier commandIdentifier)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException("commandIdentifier");
            }

            this.commandIdentifier = commandIdentifier;
        }
        private static IHystrixCommand CreateHystrixCommand(HystrixCommandIdentifier commandIdentifier)
        {
            var configurationServiceImplementation = ConfigurationManager.AppSettings[ConfigurationserviceimplementationAppsettingName];

            var configurationService = configurationServiceImplementation != null && configurationServiceImplementation.Equals("HystrixJsonConfigConfigurationService", StringComparison.InvariantCultureIgnoreCase) ? (IHystrixConfigurationService) new HystrixJsonConfigConfigurationService(commandIdentifier) : (IHystrixConfigurationService) new HystrixWebConfigConfigurationService(commandIdentifier);

            var commandMetrics    = new HystrixCommandMetrics(commandIdentifier, configurationService);
            var timeoutWrapper    = new HystrixTimeoutWrapper(commandIdentifier, configurationService);
            var circuitBreaker    = new HystrixCircuitBreaker(commandIdentifier, configurationService, commandMetrics);
            var threadPoolMetrics = new HystrixThreadPoolMetrics(commandIdentifier, configurationService);

            return(new HystrixCommand(commandIdentifier, timeoutWrapper, circuitBreaker, commandMetrics, threadPoolMetrics, configurationService));
        }
Пример #6
0
        public HystrixTimeoutWrapper(HystrixCommandIdentifier commandIdentifier, IHystrixConfigurationService configurationService)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException(nameof(commandIdentifier));
            }
            if (configurationService == null)
            {
                throw new ArgumentNullException(nameof(configurationService));
            }

            this.commandIdentifier    = commandIdentifier;
            this.configurationService = configurationService;
        }
        public HystrixLocalConfigurationService(HystrixCommandIdentifier commandIdentifier, HystrixLocalOptions localOptions)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException(nameof(commandIdentifier));
            }

            if (localOptions == null)
            {
                throw new ArgumentNullException(nameof(localOptions), "The option Details must be provided in order to use the HystrixLocalConfigurationService.");
            }

            options = localOptions.GetCommandOptions(commandIdentifier);
        }
Пример #8
0
        public HystrixThreadPoolMetrics(HystrixCommandIdentifier commandIdentifier, IHystrixConfigurationService configurationService)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException(nameof(commandIdentifier));
            }
            if (configurationService == null)
            {
                throw new ArgumentNullException(nameof(configurationService));
            }
            ConfigurationService = configurationService;

            counter = new HystrixRollingNumber(configurationService.GetMetricsRollingStatisticalWindowInMilliseconds(), configurationService.GetMetricsRollingStatisticalWindowBuckets());
        }
        private static IHystrixCommand CreateHystrixCommand(HystrixCommandIdentifier commandIdentifier, HystrixOptions options)
        {
            var configurationServiceImplementation = options.ConfigurationServiceImplementation;

            var configurationService =
                configurationServiceImplementation != null && configurationServiceImplementation.Equals("HystrixJsonConfigConfigurationService", StringComparison.OrdinalIgnoreCase)
                ? (IHystrixConfigurationService) new HystrixJsonConfigConfigurationService(commandIdentifier, options.JsonConfigurationSourceOptions)
                : new HystrixLocalConfigurationService(commandIdentifier, options.LocalOptions);

            var commandMetrics    = new HystrixCommandMetrics(commandIdentifier, configurationService);
            var timeoutWrapper    = new HystrixTimeoutWrapper(commandIdentifier, configurationService);
            var circuitBreaker    = new HystrixCircuitBreaker(commandIdentifier, configurationService, commandMetrics);
            var threadPoolMetrics = new HystrixThreadPoolMetrics(commandIdentifier, configurationService);

            return(new HystrixCommand(commandIdentifier, timeoutWrapper, circuitBreaker, commandMetrics, threadPoolMetrics, configurationService));
        }
        public HystrixJsonConfigConfigurationService(HystrixCommandIdentifier commandIdentifier)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException("commandIdentifier");
            }

            this.commandIdentifier = commandIdentifier;

            LoadWebConfigValues();

            // load remote config synchronous first time (might throw an aggregate exception)
            LoadRemoteConfigInternal(60000).Wait();

            LoadRemoteConfigAfterInterval();
        }
Пример #11
0
        public HystrixJsonConfigConfigurationService(HystrixCommandIdentifier commandIdentifier, HystrixJsonConfigurationSourceOptions options)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException(nameof(commandIdentifier));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.commandIdentifier = commandIdentifier;

            pollingIntervalInMillisecond = options.PollingIntervalInMilliseconds;

            log.InfoFormat("Loading web config values for group {0} and key {1}", commandIdentifier.GroupKey, commandIdentifier.CommandKey);

            log.InfoFormat("PollingIntervalInMillisecond for group {0} and key {1} is {2}", commandIdentifier.GroupKey, commandIdentifier.CommandKey, pollingIntervalInMillisecond);

            log.InfoFormat("BaseLocation for group {0} and key {1} is {2}", commandIdentifier.GroupKey, commandIdentifier.CommandKey, options.BaseLocation);

            log.InfoFormat("LocationPattern for group {0} and key {1} is {2}", commandIdentifier.GroupKey, commandIdentifier.CommandKey, options.LocationPattern);

            Uri baseLocationUrl;

            if (!Uri.TryCreate(EnsureTrailingSlash(options.BaseLocation), UriKind.Absolute, out baseLocationUrl))
            {
                throw new ConfigurationException("Options.BaseLocation has to contain a valid url.");
            }

            if (!Uri.TryCreate(baseLocationUrl, string.Format(options.LocationPattern, commandIdentifier.GroupKey, commandIdentifier.CommandKey), out configurationFileUrl))
            {
                throw new ConfigurationException("Options.BaseLocation has to contain a valid url.");
            }

            if (!Uri.TryCreate(baseLocationUrl, "Default.json", out defaultConfigurationFileUrl))
            {
                throw new ConfigurationException("Options.BaseLocation has to contain a valid url.");
            }

            // load remote config synchronous first time (might throw an aggregate exception)
            LoadRemoteConfigInternal(60000).Wait();

            LoadRemoteConfigAfterInterval();
        }
        public HystrixCommandMetrics(DateTimeProvider dateTimeProvider, HystrixCommandIdentifier commandIdentifier, IHystrixConfigurationService configurationService)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException(nameof(commandIdentifier));
            }
            if (configurationService == null)
            {
                throw new ArgumentNullException(nameof(configurationService));
            }

            this.dateTimeProvider     = dateTimeProvider;
            this.configurationService = configurationService;

            percentileExecution = new HystrixRollingPercentile(configurationService.GetMetricsRollingPercentileWindowInMilliseconds(), configurationService.GetMetricsRollingPercentileWindowBuckets(), configurationService.GetMetricsRollingPercentileBucketSize(), configurationService);
            percentileTotal     = new HystrixRollingPercentile(configurationService.GetMetricsRollingPercentileWindowInMilliseconds(), configurationService.GetMetricsRollingPercentileWindowBuckets(), configurationService.GetMetricsRollingPercentileBucketSize(), configurationService);

            counter = new HystrixRollingNumber(configurationService.GetMetricsRollingStatisticalWindowInMilliseconds(), configurationService.GetMetricsRollingStatisticalWindowBuckets());
        }
Пример #13
0
        public HystrixCircuitBreaker(DateTimeProvider dateTimeProvider, HystrixCommandIdentifier commandIdentifier, IHystrixConfigurationService configurationService, IHystrixCommandMetrics commandMetrics)
        {
            if (commandIdentifier == null)
            {
                throw new ArgumentNullException("commandIdentifier");
            }
            if (configurationService == null)
            {
                throw new ArgumentNullException("configurationService");
            }
            if (commandMetrics == null)
            {
                throw new ArgumentNullException("commandMetrics");
            }

            this.dateTimeProvider     = dateTimeProvider;
            this.commandIdentifier    = commandIdentifier;
            this.configurationService = configurationService;
            this.commandMetrics       = commandMetrics;
        }
 public bool Equals(HystrixCommandIdentifier obj)
 {
     return(obj != null && obj.GroupKey.Equals(GroupKey, StringComparison.InvariantCultureIgnoreCase) && obj.CommandKey.Equals(CommandKey, StringComparison.InvariantCultureIgnoreCase));
 }
 public HystrixCommandMetrics(HystrixCommandIdentifier commandIdentifier, IHystrixConfigurationService configurationService)
     : this(new DateTimeProvider(), commandIdentifier, configurationService)
 {
 }
 public IHystrixCommand GetHystrixCommand(HystrixCommandIdentifier commandIdentifier)
 {
     return(new FakeHystrixCommand(commandIdentifier, runFallbackOrThrowException));
 }
 public HystrixCircuitBreaker(HystrixCommandIdentifier commandIdentifier, IHystrixConfigurationService configurationService, IHystrixCommandMetrics commandMetrics)
     : this(new DateTimeProvider(), commandIdentifier, configurationService, commandMetrics)
 {
 }
Пример #18
0
 public FakeHystrixCommand(HystrixCommandIdentifier commandIdentifier, bool runFallbackOrThrowException)
 {
     this.runFallbackOrThrowException = runFallbackOrThrowException;
     CommandIdentifier = commandIdentifier;
 }
Пример #19
0
 public HystrixCommandOptions GetCommandOptions(HystrixCommandIdentifier id) => GetCommandOptions(id.GroupKey, id.CommandKey);