public void RegisterConcurrencyStrategy(IHystrixConcurrencyStrategy implementation) { if (!this.concurrencyStrategy.CompareAndSet(null, implementation)) { throw new InvalidOperationException("Another strategy was alread registered."); } }
private static HystrixRequestCache GetInstance(RequestCacheKey rcKey, IHystrixConcurrencyStrategy concurrencyStrategy) { return(caches.GetOrAdd(rcKey, w => { return new HystrixRequestCache(rcKey, 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; }
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); }
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(); } }
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(); } }
public static HystrixRequestCache GetInstance(IHystrixCollapserKey key, IHystrixConcurrencyStrategy concurrencyStrategy) { return(GetInstance(new RequestCacheKey(key, concurrencyStrategy), concurrencyStrategy)); }
private HystrixRequestCache(RequestCacheKey rcKey, IHystrixConcurrencyStrategy concurrencyStrategy) { this.rcKey = rcKey; this.concurrencyStrategy = concurrencyStrategy; }
/** * {@link HystrixRequestLog} for current request as defined by {@link HystrixRequestContext}. * * @return {@link HystrixRequestLog} */ public static HystrixRequestLog GetCurrentRequest(IHystrixConcurrencyStrategy concurrencyStrategy) { return currentRequestLog.Get(concurrencyStrategy); }
/** * {@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; }