Пример #1
0
 public RequestCollapserFactory(IHystrixCollapserKey collapserKey, RequestCollapserScope scope, ICollapserTimer timer, IHystrixCollapserOptions properties)
 {
     /* strategy: ConcurrencyStrategy */
     concurrencyStrategy = HystrixPlugins.ConcurrencyStrategy;
     this.timer          = timer;
     Scope        = scope;
     CollapserKey = collapserKey;
     Properties   = properties;
 }
        public HystrixCollapserOptions(IHystrixCollapserKey key, RequestCollapserScope scope, IHystrixCollapserOptions defaults = null, IHystrixDynamicOptions dynamic = null)
            : base(dynamic)
        {
            this.CollapserKey = key;
            this.Scope        = scope;
            this.defaults     = defaults;

            MaxRequestsInBatch       = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "maxRequestsInBatch", DEFAULT_MAX_REQUESTS_IN_BATCH, defaults?.MaxRequestsInBatch);
            TimerDelayInMilliseconds = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "timerDelayInMilliseconds", DEFAULT_TIMER_DELAY_IN_MILLISECONDS, defaults?.TimerDelayInMilliseconds);
            RequestCacheEnabled      = GetBoolean(HYSTRIX_COLLAPSER_PREFIX, key.Name, "requestCache.enabled", DEFAULT_REQUEST_CACHE_ENABLED, defaults?.RequestCacheEnabled);
            MetricsRollingStatisticalWindowInMilliseconds = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingStats.timeInMilliseconds", DEFAULT_METRICS_ROLLING_STATISTICAL_WINDOW, defaults?.MetricsRollingStatisticalWindowInMilliseconds);
            MetricsRollingStatisticalWindowBuckets        = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingStats.numBuckets", DEFAULT_METRICS_ROLLING_STATISTICAL_WINDOW_BUCKETS, defaults?.MetricsRollingStatisticalWindowBuckets);
            MetricsRollingPercentileEnabled = GetBoolean(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingPercentile.enabled", DEFAULT_METRICS_ROLLING_PERCENTILE_ENABLED, defaults?.MetricsRollingPercentileEnabled);
            MetricsRollingPercentileWindowInMilliseconds = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingPercentile.timeInMilliseconds", DEFAULT_METRICS_ROLLING_PERCENTILE_WINDOW, defaults?.MetricsRollingPercentileWindowInMilliseconds);
            MetricsRollingPercentileWindowBuckets        = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingPercentile.numBuckets", DEFAULT_METRICS_ROLLING_PERCENTILE_WINDOW_BUCKETS, defaults?.MetricsRollingPercentileWindowBuckets);
            MetricsRollingPercentileBucketSize           = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingPercentile.bucketSize", DEFAULT_METRICS_ROLLING_PERCENTILE_BUCKET_SIZE, defaults?.MetricsRollingPercentileBucketSize);
        }
        public HystrixCollapserOptions(IHystrixCollapserKey key, RequestCollapserScope scope, IHystrixCollapserOptions defaults = null, IHystrixDynamicOptions dynamic = null)
            : base(dynamic)
        {
            this.CollapserKey = key;
            this.Scope        = scope;
            this.defaults     = defaults;

            this.MaxRequestsInBatch       = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "maxRequestsInBatch", default_maxRequestsInBatch, defaults?.MaxRequestsInBatch);
            this.TimerDelayInMilliseconds = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "timerDelayInMilliseconds", default_timerDelayInMilliseconds, defaults?.TimerDelayInMilliseconds);
            this.RequestCacheEnabled      = GetBoolean(HYSTRIX_COLLAPSER_PREFIX, key.Name, "requestCache.enabled", default_requestCacheEnabled, defaults?.RequestCacheEnabled);
            this.MetricsRollingStatisticalWindowInMilliseconds = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingStats.timeInMilliseconds", default_metricsRollingStatisticalWindow, defaults?.MetricsRollingStatisticalWindowInMilliseconds);
            this.MetricsRollingStatisticalWindowBuckets        = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingStats.numBuckets", default_metricsRollingStatisticalWindowBuckets, defaults?.MetricsRollingStatisticalWindowBuckets);
            this.MetricsRollingPercentileEnabled = GetBoolean(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingPercentile.enabled", default_metricsRollingPercentileEnabled, defaults?.MetricsRollingPercentileEnabled);
            this.MetricsRollingPercentileWindowInMilliseconds = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingPercentile.timeInMilliseconds", default_metricsRollingPercentileWindow, defaults?.MetricsRollingPercentileWindowInMilliseconds);
            this.MetricsRollingPercentileWindowBuckets        = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingPercentile.numBuckets", default_metricsRollingPercentileWindowBuckets, defaults?.MetricsRollingPercentileWindowBuckets);
            this.MetricsRollingPercentileBucketSize           = GetInteger(HYSTRIX_COLLAPSER_PREFIX, key.Name, "metrics.rollingPercentile.bucketSize", default_metricsRollingPercentileBucketSize, defaults?.MetricsRollingPercentileBucketSize);
        }
        protected HystrixCollapser(IHystrixCollapserKey collapserKey, RequestCollapserScope scope, ICollapserTimer timer, IHystrixCollapserOptions optionsDefault, HystrixCollapserMetrics metrics)
        {
            if (collapserKey == null || collapserKey.Name.Trim().Equals(""))
            {
                string defaultKeyName = GetDefaultNameFromClass(GetType());
                collapserKey = HystrixCollapserKeyDefault.AsKey(defaultKeyName);
            }
            IHystrixCollapserOptions options = HystrixOptionsFactory.GetCollapserOptions(collapserKey, optionsDefault);

            this.collapserFactory = new RequestCollapserFactory(collapserKey, scope, timer, options);
            this.requestCache     = HystrixRequestCache.GetInstance(collapserKey);

            if (metrics == null)
            {
                this.metrics = HystrixCollapserMetrics.GetInstance(collapserKey, options);
            }
            else
            {
                this.metrics = metrics;
            }

            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForCollapser(collapserKey, this.metrics, options);
        }
Пример #5
0
        protected HystrixCollapser(IHystrixCollapserKey collapserKey, RequestCollapserScope scope, ICollapserTimer timer, IHystrixCollapserOptions optionsDefault, HystrixCollapserMetrics metrics)
        {
            if (collapserKey == null || string.IsNullOrWhiteSpace(collapserKey.Name))
            {
                var defaultKeyName = GetDefaultNameFromClass(GetType());
                collapserKey = HystrixCollapserKeyDefault.AsKey(defaultKeyName);
            }

            var options = HystrixOptionsFactory.GetCollapserOptions(collapserKey, optionsDefault);

            _collapserFactory = new RequestCollapserFactory(collapserKey, scope, timer, options);
            _requestCache     = HystrixRequestCache.GetInstance(collapserKey);

            if (metrics == null)
            {
                _metrics = HystrixCollapserMetrics.GetInstance(collapserKey, options);
            }
            else
            {
                _metrics = metrics;
            }

            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForCollapser(collapserKey, _metrics, options);
        }
        public static void AddHystrixCollapser <TService, TImplementation>(this IServiceCollection services, string collapserKey, RequestCollapserScope scope, IConfiguration config)
            where TService : class
            where TImplementation : class, TService
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (string.IsNullOrEmpty(collapserKey))
            {
                throw new ArgumentNullException(nameof(collapserKey));
            }

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

            AddHystrixCollapser <TService, TImplementation>(services, HystrixCollapserKeyDefault.AsKey(collapserKey), scope, config);
        }
        public static void AddHystrixCollapser <TService>(this IServiceCollection services, IHystrixCollapserKey collapserKey, RequestCollapserScope scope, IConfiguration config)
            where TService : class
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            var strategy = HystrixPlugins.OptionsStrategy;
            var dynOpts  = strategy.GetDynamicOptions(config);

            var opts = new HystrixCollapserOptions(collapserKey, scope, null, dynOpts);

            services.AddTransient <TService>((p) => (TService)ActivatorUtilities.CreateInstance(p, typeof(TService), opts));
        }
Пример #8
0
 protected HystrixCollapser(IHystrixCollapserKey collapserKey, RequestCollapserScope scope, ICollapserTimer timer, IHystrixCollapserOptions options)
     : this(collapserKey, scope, timer, options, null)
 {
 }
Пример #9
0
 protected HystrixCollapser(IHystrixCollapserKey collapserKey, RequestCollapserScope scope)
     : this(new HystrixCollapserOptions(collapserKey, scope))
 {
 }
        public static void RegisterHystrixCollapser <TService, TImplementation>(this ContainerBuilder container, string collapserKey, RequestCollapserScope scope, IConfiguration config)
            where TService : class
            where TImplementation : class, TService
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (string.IsNullOrEmpty(collapserKey))
            {
                throw new ArgumentNullException(nameof(collapserKey));
            }

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

            RegisterHystrixCollapser <TService, TImplementation>(container, HystrixCollapserKeyDefault.AsKey(collapserKey), scope, config);
        }
        public static void RegisterHystrixCollapser <TService>(this ContainerBuilder container, IHystrixCollapserKey collapserKey, RequestCollapserScope scope, IConfiguration config)
            where TService : class
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

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

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

            var strategy = HystrixPlugins.OptionsStrategy;
            var dynOpts  = strategy.GetDynamicOptions(config);

            HystrixCollapserOptions opts = new HystrixCollapserOptions(collapserKey, scope, null, dynOpts);

            container.RegisterType <TService>().WithParameter(new TypedParameter(typeof(IHystrixCollapserOptions), opts)).InstancePerDependency();
        }