A key to represent a HystrixThreadPool for monitoring, metrics publishing, caching and other such uses.
Inheritance: HystrixKey
コード例 #1
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);
        }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
 /// <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);
 }
コード例 #5
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);
        }
コード例 #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);
        }
コード例 #7
0
        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);
                });
            }
        }
コード例 #8
0
 public virtual IHystrixThreadPoolProperties GetThreadPoolProperties(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return new HystrixThreadPoolPropertiesDefault(setter);
 }
コード例 #9
0
 public virtual string GetThreadPoolPropertiesCacheKey(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
 {
     return threadPoolKey.Name;
 }
コード例 #10
0
 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));
 }
コード例 #13
0
 public HystrixMetricsPublisherThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     // do nothing by default
 }
コード例 #14
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)));
 }
コード例 #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
ファイル: AtlasPublisher.cs プロジェクト: Elders/Hystrix.NET
 public IHystrixMetricsPublisherThreadPool GetMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     return new Dummy1();
 }
コード例 #17
0
 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());
 }
コード例 #18
0
 public static IHystrixMetricsPublisherThreadPool CreateOrRetrievePublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
 {
     return instance.GetPublisherForThreadPool(threadPoolKey, metrics, properties);
 }
コード例 #19
0
 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;
 }
コード例 #21
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)));
 }
コード例 #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;
 }