/// <summary> /// Check single rule for target /// </summary> /// <param name="target"></param> /// <param name="rule"></param> /// <returns></returns> protected abstract RuleCheckResult CheckSingleRule(string target, RateLimitRule rule);
/// <summary> /// Check single rule for target /// </summary> /// <param name="target"></param> /// <param name="rule"></param> /// <returns></returns> protected abstract Task <RuleCheckResult> CheckSingleRuleAsync(string target, RateLimitRule rule);
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="storage"></param> /// <param name="rule"></param> /// <returns></returns> protected abstract Task <bool> CheckSingleRuleAsync(string target, IRateLimitStorage storage, RateLimitRule <TRequest> rule);
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="storage"></param> /// <param name="rule"></param> /// <returns></returns> protected override async Task <bool> CheckSingleRuleAsync(string target, IRateLimitStorage storage, RateLimitRule <TRequest> rule) { var currentRule = rule as FixedWindowRateLimitRule <TRequest>; var countAmount = 1; var expireTimeSpan = currentRule.StatWindow; var result = await storage.FixedWindowIncrementAsync(target, countAmount, expireTimeSpan, currentRule.LimitNumber, rule.LockSeconds); return(result.Item1); }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="storage"></param> /// <param name="rule"></param> /// <returns></returns> protected abstract bool CheckSingleRule(string target, IRateLimitStorage storage, RateLimitRule <TRequest> rule);
/// <summary> /// Check single rule for target /// </summary> /// <param name="target"></param> /// <param name="rule"></param> /// <param name="rateLimitAttrData"></param> /// <returns></returns> protected abstract Task <RuleCheckResult> CheckSingleRuleAsync(string target, RateLimitRule rule, RateLimitTypeAttributeJson rateLimitAttrData);
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="storage"></param> /// <param name="rule"></param> /// <returns></returns> protected override async Task <bool> CheckSingleRuleAsync(string target, IRateLimitStorage storage, RateLimitRule <TRequest> rule) { var currentRule = rule as SlidingWindowRateLimitRule <TRequest>; var result = await storage.SlidingWindowIncrementAsync(target, 1, currentRule.StatWindow, currentRule.StatPeriod, currentRule.PeriodNumber, currentRule.LimitNumber, currentRule.LockSeconds); Debug.WriteLine("check result:" + result.Item1 + "," + result.Item2); return(result.Item1); }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="storage"></param> /// <param name="rule"></param> /// <returns></returns> protected override async Task <bool> CheckSingleRuleAsync(string target, IRateLimitStorage storage, RateLimitRule <TRequest> rule) { var currentRule = rule as LeakyBucketRateLimitRule <TRequest>; var result = await storage.LeakyBucketIncrementAsync(target, 1, currentRule.Capacity, (int)currentRule.OutflowUnit.TotalMilliseconds, currentRule.OutflowQuantityPerUnit, currentRule.LockSeconds); Debug.WriteLine("check result:" + result.Item1 + "," + result.Item2); return(result.Item1); }
/// <summary> /// check single rule for target /// </summary> /// <param name="target"></param> /// <param name="storage"></param> /// <param name="rule"></param> /// <returns></returns> protected override bool CheckSingleRule(string target, IRateLimitStorage storage, RateLimitRule <TRequest> rule) { var currentRule = rule as TokenBucketRateLimitRule <TRequest>; var result = storage.TokenBucketDecrement(target, 1, currentRule.Capacity, (int)currentRule.InflowUnit.TotalMilliseconds, currentRule.InflowQuantityPerUnit, currentRule.LockSeconds); Debug.WriteLine("check result:" + result.Item1 + "," + result.Item2); return(result.Item1); }