Exemple #1
0
 public static void RegisterConcurrencyStrategy(HystrixConcurrencyStrategy impl)
 {
     if (!concurrencyStrategy.CompareAndSet(null, impl))
     {
         throw new InvalidOperationException("Another strategy was already registered.");
     }
 }
Exemple #2
0
 internal RequestCollapser(HystrixCollapser <BatchReturnType, RequestResponseType, RequestArgumentType> commandCollapser, IHystrixCollapserOptions properties, ICollapserTimer timer, HystrixConcurrencyStrategy concurrencyStrategy)
 {
     this.commandCollapser    = commandCollapser; // the command with implementation of abstract methods we need
     this.concurrencyStrategy = concurrencyStrategy;
     this.properties          = properties;
     this.timer  = timer;
     batch.Value = new RequestBatch <BatchReturnType, RequestResponseType, RequestArgumentType>(properties, commandCollapser, properties.MaxRequestsInBatch);
 }
Exemple #3
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 void TestCacheWithoutRequestContext()
        {
            HystrixConcurrencyStrategy strategy = HystrixConcurrencyStrategyDefault.GetInstance();

            context.Dispose();

            HystrixRequestCache cache1 = HystrixRequestCache.GetInstance(HystrixCommandKeyDefault.AsKey("command1"));
            Task <string>       t1     = Task.FromResult("a1");

            // this should fail, as there's no HystrixRequestContext instance to place the cache into
            Assert.Throws <InvalidOperationException>(() => { cache1.PutIfAbsent("valueA", t1); });
        }
Exemple #5
0
        public HystrixThreadPoolDefault(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions propertiesDefaults)
        {
            this.properties = HystrixOptionsFactory.GetThreadPoolOptions(threadPoolKey, propertiesDefaults);
            this.properties = propertiesDefaults ?? new HystrixThreadPoolOptions(threadPoolKey);
            HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.ConcurrencyStrategy;

            this.queueSize     = properties.MaxQueueSize;
            this.metrics       = HystrixThreadPoolMetrics.GetInstance(threadPoolKey, concurrencyStrategy.GetTaskScheduler(properties), properties);
            this.taskScheduler = this.metrics.TaskScheduler;

            /* strategy: HystrixMetricsPublisherThreadPool */
            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForThreadPool(threadPoolKey, this.metrics, this.properties);
        }
        public void TestClearCache()
        {
            HystrixConcurrencyStrategy strategy = HystrixConcurrencyStrategyDefault.GetInstance();

            try
            {
                HystrixRequestCache cache1 = HystrixRequestCache.GetInstance(HystrixCommandKeyDefault.AsKey("command1"));
                Task <string>       t1     = Task.FromResult("a1");
                cache1.PutIfAbsent("valueA", t1);
                Assert.Equal("a1", cache1.Get <Task <string> >("valueA").Result);
                cache1.Clear("valueA");
                Assert.Null(cache1.Get <Task <string> >("valueA"));
            }
            catch (Exception e)
            {
                Assert.False(true, "Exception: " + e.Message);
                output.WriteLine(e.ToString());
            }
        }
Exemple #7
0
 public RequestCollapserRequestVariable(HystrixCollapser <BatchReturnType, ResponseType, RequestArgumentType> commandCollapser, IHystrixCollapserOptions properties, ICollapserTimer timer, HystrixConcurrencyStrategy concurrencyStrategy)
     : base(() => new RequestCollapser <BatchReturnType, ResponseType, RequestArgumentType>(commandCollapser, properties, timer, concurrencyStrategy), (collapser) => collapser.Shutdown())
 {
 }