A key to represent a HystrixThreadPool for monitoring, metrics publishing, caching and other such uses.
Наследование: HystrixKey
        /// <summary>
        /// Gets the <see cref="HystrixThreadPoolMetrics"/> instance for a given <see cref="HystrixThreadPoolKey"/> or null if none exists.
        /// </summary>
        /// <param name="key">Key of the tracked thread pool.</param>
        /// <returns>A thread pool metrics instance of the specified thread pool.</returns>
        public static HystrixThreadPoolMetrics GetInstance(HystrixThreadPoolKey key)
        {
            HystrixThreadPoolMetrics threadPoolMetrics = null;

            Metrics.TryGetValue(key, out threadPoolMetrics);
            return(threadPoolMetrics);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HystrixThreadPoolMetrics"/> class.
 /// </summary>
 /// <param name="threadPoolKey">The key of the parent thread pool.</param>
 /// <param name="threadPool">The <see cref="ThreadPoolExecutor"/> of the parent thread pool.</param>
 /// <param name="properties">The properties of the parent thread pool.</param>
 private HystrixThreadPoolMetrics(HystrixThreadPoolKey threadPoolKey, ThreadPoolExecutor threadPool, IHystrixThreadPoolProperties properties)
 {
     this.threadPoolKey = threadPoolKey;
     this.threadPool = threadPool;
     this.properties = properties;
     this.counter = new HystrixRollingNumber(properties.MetricsRollingStatisticalWindowInMilliseconds, properties.MetricsRollingStatisticalWindowBuckets);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HystrixThreadPoolMetrics"/> class.
 /// </summary>
 /// <param name="threadPoolKey">The key of the parent thread pool.</param>
 /// <param name="threadPool">The <see cref="ThreadPoolExecutor"/> of the parent thread pool.</param>
 /// <param name="properties">The properties of the parent thread pool.</param>
 private HystrixThreadPoolMetrics(HystrixThreadPoolKey threadPoolKey, ThreadPoolExecutor threadPool, IHystrixThreadPoolProperties properties)
 {
     this.threadPoolKey = threadPoolKey;
     this.threadPool    = threadPool;
     this.properties    = properties;
     this.counter       = new HystrixRollingNumber(properties.MetricsRollingStatisticalWindowInMilliseconds, properties.MetricsRollingStatisticalWindowBuckets);
 }
Пример #4
0
 public IHystrixThreadPoolProperties GetThreadPoolProperties(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     if (setter == null)
     {
         setter = UnitTestSetterFactory.GetThreadPoolPropertiesSetter();
     }
     return new MockingHystrixThreadPoolProperties(setter);
 }
        /// <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);
        }
Пример #6
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);
        }
        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);
                });
            }
        }
 public virtual IHystrixThreadPoolProperties GetThreadPoolProperties(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return new HystrixThreadPoolPropertiesDefault(setter);
 }
 public virtual string GetThreadPoolPropertiesCacheKey(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return threadPoolKey.Name;
 }
 public IHystrixMetricsPublisherThreadPool GetMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     return new HystrixDelegateMetricsPublisherThreadPool(() => this.threadCounter.IncrementAndGet());
 }
Пример #11
0
 public HystrixCommandSetter AndThreadPoolKey(HystrixThreadPoolKey threadPoolKey)
 {
     ThreadPoolKey = threadPoolKey;
     return this;
 }
Пример #12
0
 /// <summary>
 /// Gets the <see cref="HystrixThreadPoolMetrics"/> instance for a given <see cref="HystrixThreadPoolKey"/>.
 /// If no metrics exists for the specified key, a new one will be created from the specified threadPool and setter.
 /// </summary>
 /// <param name="key">Key of the tracked thread pool.</param>
 /// <param name="threadPool">The thread pool executor of the tracked pool.</param>
 /// <param name="properties">The properties of the tracked pool.</param>
 /// <returns>A new or an existing thread pool metrics instance of the specified key.</returns>
 public static HystrixThreadPoolMetrics GetInstance(HystrixThreadPoolKey key, ThreadPoolExecutor threadPool, IHystrixThreadPoolProperties properties)
 {
     return Metrics.GetOrAdd(key, w => new HystrixThreadPoolMetrics(key, threadPool, properties));
 }
 public HystrixMetricsPublisherThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     // do nothing by default
 }
 /// <summary>
 /// Gets the <see cref="HystrixThreadPoolMetrics"/> instance for a given <see cref="HystrixThreadPoolKey"/>.
 /// If no metrics exists for the specified key, a new one will be created from the specified threadPool and setter.
 /// </summary>
 /// <param name="key">Key of the tracked thread pool.</param>
 /// <param name="threadPool">The thread pool executor of the tracked pool.</param>
 /// <param name="properties">The properties of the tracked pool.</param>
 /// <returns>A new or an existing thread pool metrics instance of the specified key.</returns>
 public static HystrixThreadPoolMetrics GetInstance(HystrixThreadPoolKey key, ThreadPoolExecutor threadPool, IHystrixThreadPoolProperties properties)
 {
     return(Metrics.GetOrAdd(key, w => new HystrixThreadPoolMetrics(key, threadPool, properties)));
 }
Пример #15
0
 /// <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));
 }
Пример #16
0
 public IHystrixMetricsPublisherThreadPool GetMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     return new Dummy1();
 }
 public IHystrixMetricsPublisherThreadPool GetPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     return this.threadPoolPublishers.GetOrAdd(threadPoolKey.Name,
         w => this.strategy.GetMetricsPublisherForThreadPool(threadPoolKey, metrics, properties),
         w => w.Initialize());
 }
 public static IHystrixMetricsPublisherThreadPool CreateOrRetrievePublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     return instance.GetPublisherForThreadPool(threadPoolKey, metrics, properties);
 }
 public virtual IHystrixMetricsPublisherThreadPool GetMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     return new HystrixMetricsPublisherThreadPoolDefault(threadPoolKey, metrics, properties);
 }
Пример #20
0
 public string GetThreadPoolPropertiesCacheKey(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return null;
 }
 /// <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)));
 }
Пример #22
0
 /// <summary>
 /// Gets the <see cref="HystrixThreadPoolMetrics"/> instance for a given <see cref="HystrixThreadPoolKey"/> or null if none exists.
 /// </summary>
 /// <param name="key">Key of the tracked thread pool.</param>
 /// <returns>A thread pool metrics instance of the specified thread pool.</returns>
 public static HystrixThreadPoolMetrics GetInstance(HystrixThreadPoolKey key)
 {
     HystrixThreadPoolMetrics threadPoolMetrics = null;
     Metrics.TryGetValue(key, out threadPoolMetrics);
     return threadPoolMetrics;
 }