Ejemplo n.º 1
0
 public void RegisterConcurrencyStrategy(IHystrixConcurrencyStrategy implementation)
 {
     if (!this.concurrencyStrategy.CompareAndSet(null, implementation))
     {
         throw new InvalidOperationException("Another strategy was alread registered.");
     }
 }
Ejemplo n.º 2
0
 private static HystrixRequestCache GetInstance(RequestCacheKey rcKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     return(caches.GetOrAdd(rcKey, w =>
     {
         return new HystrixRequestCache(rcKey, concurrencyStrategy);
     }));
 }
Ejemplo 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;
 }
Ejemplo 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;
 }
Ejemplo n.º 5
0
 public RequestCacheKey(IHystrixCollapserKey collapserKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     type = 2;
     if (collapserKey == null)
     {
         this.key = null;
     }
     else
     {
         this.key = collapserKey.Name;
     }
     this.concurrencyStrategy = concurrencyStrategy;
 }
Ejemplo n.º 6
0
 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;
        }
Ejemplo 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);
        }
Ejemplo 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();
            }
        }
Ejemplo 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();
            }
        }
Ejemplo n.º 11
0
 public static HystrixRequestCache GetInstance(IHystrixCollapserKey key, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     return(GetInstance(new RequestCacheKey(key, concurrencyStrategy), concurrencyStrategy));
 }
Ejemplo n.º 12
0
 private HystrixRequestCache(RequestCacheKey rcKey, IHystrixConcurrencyStrategy concurrencyStrategy)
 {
     this.rcKey = rcKey;
     this.concurrencyStrategy = concurrencyStrategy;
 }
Ejemplo 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);
 }
Ejemplo 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;
 }