Fluent interface that allows chained setting of properties that can be passed into a IHystrixThreadPool via a HystrixCommand constructor to inject instance specific property.
        public MockingHystrixThreadPoolProperties(HystrixThreadPoolPropertiesSetter setter)
        {
            if (setter == null)
                throw new ArgumentNullException("setter");

            this.setter = setter;
        }
 public IHystrixThreadPoolProperties GetThreadPoolProperties(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     if (setter == null)
     {
         setter = UnitTestSetterFactory.GetThreadPoolPropertiesSetter();
     }
     return new MockingHystrixThreadPoolProperties(setter);
 }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HystrixThreadPoolDefault"/> class.
        /// </summary>
        /// <param name="threadPoolKey">The key of this thread pool.</param>
        /// <param name="setter">The default properties of this thread pool.</param>
        public HystrixThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
        {
            this.properties = HystrixPropertiesFactory.GetThreadPoolProperties(threadPoolKey, setter);
            this.queue      = HystrixPlugins.Instance.ConcurrencyStrategy.GetBlockingQueue(this.properties.MaxQueueSize.Get());
            this.threadPool = HystrixPlugins.Instance.ConcurrencyStrategy.GetThreadPool(threadPoolKey, this.properties.CoreSize, this.properties.CoreSize, this.properties.KeepAliveTime, this.queue);
            this.metrics    = HystrixThreadPoolMetrics.GetInstance(threadPoolKey, this.threadPool, this.properties);

            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForThreadPool(threadPoolKey, this.metrics, this.properties);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HystrixThreadPoolDefault"/> class.
        /// </summary>
        /// <param name="threadPoolKey">The key of this thread pool.</param>
        /// <param name="setter">The default properties of this thread pool.</param>
        public HystrixThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
        {
            this.properties = HystrixPropertiesFactory.GetThreadPoolProperties(threadPoolKey, setter);
            this.queue = HystrixPlugins.Instance.ConcurrencyStrategy.GetBlockingQueue(this.properties.MaxQueueSize.Get());
            this.threadPool = HystrixPlugins.Instance.ConcurrencyStrategy.GetThreadPool(threadPoolKey, this.properties.CoreSize, this.properties.CoreSize, this.properties.KeepAliveTime, this.queue);
            this.metrics = HystrixThreadPoolMetrics.GetInstance(threadPoolKey, this.threadPool, this.properties);

            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForThreadPool(threadPoolKey, this.metrics, this.properties);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HystrixThreadPoolPropertiesDefault"/> class.
        /// </summary>
        /// <param name="setter">The property value provider.</param>
        public HystrixThreadPoolPropertiesDefault(HystrixThreadPoolPropertiesSetter setter)
        {
            if (setter == null)
            {
                throw new ArgumentNullException("setter");
            }

            this.CoreSize = HystrixPropertyFactory.AsProperty(setter.CoreSize, DefaultCoreSize);
            this.KeepAliveTime = HystrixPropertyFactory.AsProperty(setter.KeepAliveTime, DefaultKeepAliveTime);
            this.MaxQueueSize = HystrixPropertyFactory.AsProperty(setter.MaxQueueSize, DefaultMaxQueueSize);
            this.QueueSizeRejectionThreshold = HystrixPropertyFactory.AsProperty(setter.QueueSizeRejectionThreshold, DefaultQueueSizeRejectionThreshold);
            this.MetricsRollingStatisticalWindowInMilliseconds = HystrixPropertyFactory.AsProperty(setter.MetricsRollingStatisticalWindowInMilliseconds, DefaultMetricsRollingStatisticalWindowInMilliseconds);
            this.MetricsRollingStatisticalWindowBuckets = HystrixPropertyFactory.AsProperty(setter.MetricsRollingStatisticalWindowBuckets, DefaultThreadPoolRollingNumberStatisticalWindowBuckets);
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HystrixThreadPoolPropertiesDefault"/> class.
        /// </summary>
        /// <param name="setter">The property value provider.</param>
        public HystrixThreadPoolPropertiesDefault(HystrixThreadPoolPropertiesSetter setter)
        {
            if (setter == null)
            {
                throw new ArgumentNullException("setter");
            }

            this.CoreSize      = HystrixPropertyFactory.AsProperty(setter.CoreSize, DefaultCoreSize);
            this.KeepAliveTime = HystrixPropertyFactory.AsProperty(setter.KeepAliveTime, DefaultKeepAliveTime);
            this.MaxQueueSize  = HystrixPropertyFactory.AsProperty(setter.MaxQueueSize, DefaultMaxQueueSize);
            this.QueueSizeRejectionThreshold = HystrixPropertyFactory.AsProperty(setter.QueueSizeRejectionThreshold, DefaultQueueSizeRejectionThreshold);
            this.MetricsRollingStatisticalWindowInMilliseconds = HystrixPropertyFactory.AsProperty(setter.MetricsRollingStatisticalWindowInMilliseconds, DefaultMetricsRollingStatisticalWindowInMilliseconds);
            this.MetricsRollingStatisticalWindowBuckets        = HystrixPropertyFactory.AsProperty(setter.MetricsRollingStatisticalWindowBuckets, DefaultThreadPoolRollingNumberStatisticalWindowBuckets);
        }
        public static IHystrixThreadPoolProperties GetThreadPoolProperties(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
        {
            if (threadPoolKey == null)
                throw new ArgumentNullException("threadPoolKey");

            IHystrixPropertiesStrategy strategy = HystrixPlugins.Instance.PropertiesStrategy;
            string cacheKey = strategy.GetThreadPoolPropertiesCacheKey(threadPoolKey, setter);
            if (String.IsNullOrEmpty(cacheKey))
            {
                return strategy.GetThreadPoolProperties(threadPoolKey, setter);
            }
            else
            {
                return threadPoolProperties.GetOrAdd(cacheKey, w =>
                {
                    if (setter == null)
                    {
                        setter = new HystrixThreadPoolPropertiesSetter();
                    }

                    return strategy.GetThreadPoolProperties(threadPoolKey, setter);
                });
            }
        }
 /// <summary>
 /// Gets the <see cref="IHystrixThreadPool"/> instance for a given <see cref="HystrixThreadPoolKey"/>.
 /// If no thread pool exists for the specified key, a new one will be created from the specified setter.
 /// This is thread-safe and ensures only 1 <see cref="IHystrixThreadPool"/> per <see cref="HystrixThreadPoolKey"/>.
 /// </summary>
 /// <param name="threadPoolKey">Key of the requested thread pool.</param>
 /// <param name="setter">The setter to construct the new thread pool.</param>
 /// <returns>A new or an existing thread pool instance.</returns>
 internal static IHystrixThreadPool GetInstance(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return(ThreadPools.GetOrAdd(threadPoolKey, w => new HystrixThreadPoolDefault(threadPoolKey, setter)));
 }
 /// <summary>
 /// Gets the <see cref="IHystrixThreadPool"/> instance for a given <see cref="HystrixThreadPoolKey"/>.
 /// If no thread pool exists for the specified key, a new one will be created from the specified setter.
 /// This is thread-safe and ensures only 1 <see cref="IHystrixThreadPool"/> per <see cref="HystrixThreadPoolKey"/>.
 /// </summary>
 /// <param name="threadPoolKey">Key of the requested thread pool.</param>
 /// <param name="setter">The setter to construct the new thread pool.</param>
 /// <returns>A new or an existing thread pool instance.</returns>
 internal static IHystrixThreadPool GetInstance(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return ThreadPools.GetOrAdd(threadPoolKey, w => new HystrixThreadPoolDefault(threadPoolKey, setter));
 }
 public virtual string GetThreadPoolPropertiesCacheKey(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return threadPoolKey.Name;
 }
 public virtual IHystrixThreadPoolProperties GetThreadPoolProperties(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return new HystrixThreadPoolPropertiesDefault(setter);
 }
 public string GetThreadPoolPropertiesCacheKey(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return null;
 }
 public HystrixCommandSetter AndThreadPoolPropertiesDefaults(HystrixThreadPoolPropertiesSetter threadPoolPropertiesDefaults)
 {
     ThreadPoolPropertiesDefaults = threadPoolPropertiesDefaults;
     return this;
 }