Esempio n. 1
0
 public void RegisterConcurrencyStrategy(IHystrixConcurrencyStrategy implementation)
 {
     if (!this.concurrencyStrategy.CompareAndSet(null, implementation))
     {
         throw new InvalidOperationException("Another strategy was alread registered.");
     }
 }
Esempio n. 2
0
 private static HystrixRequestCache GetInstance(RequestCacheKey rcKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     return(caches.GetOrAdd(rcKey, w =>
     {
         return new HystrixRequestCache(rcKey, concurrencyStrategy);
     }));
 }
Esempio n. 3
0
 public RequestCacheKey(IHystrixCollapserKey collapserKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     type = 2;
     if (collapserKey == null)
     {
         this.key = null;
     }
     else
     {
         this.key = collapserKey.Name;
     }
     this.concurrencyStrategy = concurrencyStrategy;
 }
Esempio n. 4
0
 public RequestCacheKey(HystrixCommandKey commandKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     type = 1;
     if (commandKey == null)
     {
         this.key = null;
     }
     else
     {
         this.key = commandKey.Name;
     }
     this.concurrencyStrategy = concurrencyStrategy;
 }
 public RequestCacheKey(IHystrixCollapserKey collapserKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     type = 2;
     if (collapserKey == null)
     {
         this.key = null;
     }
     else
     {
         this.key = collapserKey.Name;
     }
     this.concurrencyStrategy = concurrencyStrategy;
 }
 public RequestCacheKey(HystrixCommandKey commandKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     type = 1;
     if (commandKey == null)
     {
         this.key = null;
     }
     else
     {
         this.key = commandKey.Name;
     }
     this.concurrencyStrategy = concurrencyStrategy;
 }
        public object Get(IHystrixConcurrencyStrategy concurrencyStrategy)
        {
            HystrixRequestVariableCacheKey key = new HystrixRequestVariableCacheKey(this, concurrencyStrategy);
            IHystrixRequestVariable rvInstance = requestVariableInstance.GetOrAdd(key, w =>
            {
                if (requestVariableInstance.Count > 100)
                {
                    logger.Warn("Over 100 instances of HystrixRequestVariable are being stored. This is likely the sign of a memory leak caused by using unique instances of HystrixConcurrencyStrategy instead of a single instance.");
                }

                return concurrencyStrategy.GetRequestVariable(lifeCycleMethods);
            });

            return rvInstance.Value;
        }
Esempio n. 8
0
        public object Get(IHystrixConcurrencyStrategy concurrencyStrategy)
        {
            HystrixRequestVariableCacheKey key        = new HystrixRequestVariableCacheKey(this, concurrencyStrategy);
            IHystrixRequestVariable        rvInstance = requestVariableInstance.GetOrAdd(key, w =>
            {
                if (requestVariableInstance.Count > 100)
                {
                    logger.Warn("Over 100 instances of HystrixRequestVariable are being stored. This is likely the sign of a memory leak caused by using unique instances of HystrixConcurrencyStrategy instead of a single instance.");
                }

                return(concurrencyStrategy.GetRequestVariable(lifeCycleMethods));
            });

            return(rvInstance.Value);
        }
Esempio n. 9
0
        public void RequestCache_Cache()
        {
            IHystrixConcurrencyStrategy strategy = HystrixConcurrencyStrategyDefault.Instance;
            HystrixRequestContext       context  = HystrixRequestContext.InitializeContext();

            try
            {
                HystrixRequestCache cache1 = HystrixRequestCache.GetInstance("command1", strategy);
                cache1.PutIfAbsent("valueA", new TestFuture("a1"));
                cache1.PutIfAbsent("valueA", new TestFuture("a2"));
                cache1.PutIfAbsent("valueB", new TestFuture("b1"));

                HystrixRequestCache cache2 = HystrixRequestCache.GetInstance("command2", strategy);
                cache2.PutIfAbsent("valueA", new TestFuture("a3"));

                Assert.AreEqual("a1", cache1.Get <string>("valueA").Get());
                Assert.AreEqual("b1", cache1.Get <string>("valueB").Get());

                Assert.AreEqual("a3", cache2.Get <string>("valueA").Get());
                Assert.IsNull(cache2.Get <string>("valueB"));
            }
            catch (Exception e)
            {
                Assert.Fail("Exception: " + e.Message);
                Console.WriteLine(e.ToString());
            }
            finally
            {
                context.Shutdown();
            }

            context = HystrixRequestContext.InitializeContext();
            try
            {
                // with a new context  the instance should have nothing in it
                HystrixRequestCache cache = HystrixRequestCache.GetInstance("command1", strategy);
                Assert.IsNull(cache.Get <string>("valueA"));
                Assert.IsNull(cache.Get <string>("valueB"));
            }
            finally
            {
                context.Shutdown();
            }
        }
Esempio n. 10
0
        public void RequestCache_ClearCache()
        {
            IHystrixConcurrencyStrategy strategy = HystrixConcurrencyStrategyDefault.Instance;
            HystrixRequestContext       context  = HystrixRequestContext.InitializeContext();

            try
            {
                HystrixRequestCache cache1 = HystrixRequestCache.GetInstance("command1", strategy);
                cache1.PutIfAbsent("valueA", new TestFuture("a1"));
                Assert.AreEqual("a1", cache1.Get <string>("valueA").Get());
                cache1.Clear("valueA");
                Assert.IsNull(cache1.Get <string>("valueA"));
            }
            catch (Exception e)
            {
                Assert.Fail("Exception: " + e.Message);
                Console.WriteLine(e.ToString());
            }
            finally
            {
                context.Shutdown();
            }
        }
Esempio n. 11
0
 public static HystrixRequestCache GetInstance(IHystrixCollapserKey key, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     return(GetInstance(new RequestCacheKey(key, concurrencyStrategy), concurrencyStrategy));
 }
Esempio n. 12
0
 private HystrixRequestCache(RequestCacheKey rcKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     this.rcKey = rcKey;
     this.concurrencyStrategy = concurrencyStrategy;
 }
Esempio n. 13
0
 /**
  * {@link HystrixRequestLog} for current request as defined by {@link HystrixRequestContext}.
  * 
  * @return {@link HystrixRequestLog}
  */
 public static HystrixRequestLog GetCurrentRequest(IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     return currentRequestLog.Get(concurrencyStrategy);
 }
Esempio n. 14
0
 /**
  * {@link HystrixRequestLog} for current request as defined by {@link HystrixRequestContext}.
  *
  * @return {@link HystrixRequestLog}
  */
 public static HystrixRequestLog GetCurrentRequest(IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     return(currentRequestLog.Get(concurrencyStrategy));
 }
 public HystrixRequestVariableCacheKey(HystrixRequestVariableHolder rvHolder, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     this.rvHolder            = rvHolder;
     this.concurrencyStrategy = concurrencyStrategy;
 }
 public HystrixRequestVariableCacheKey(HystrixRequestVariableHolder rvHolder, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     this.rvHolder = rvHolder;
     this.concurrencyStrategy = concurrencyStrategy;
 }