using System; using System.Collections.Generic; using System.Linq; namespace Grpc.Extension.BaseService { public class ThrottleManager { private static readonly object sync = new object(); private List throttleMethods = new List(); private static Lazy instance = new Lazy(() => new ThrottleManager(), true); public static ThrottleManager Instance => instance.Value; public void Add(string fullName) { if (string.IsNullOrWhiteSpace(fullName)) return; lock (sync) { throttleMethods.Add(fullName.Trim()); throttleMethods = throttleMethods.Distinct().ToList(); } } public void Del(string fullName) { if (string.IsNullOrWhiteSpace(fullName)) return; lock (sync) { throttleMethods.Remove(fullName.Trim()); } } public bool IsThrottled(string fullName) { if (string.IsNullOrWhiteSpace(fullName)) return false; lock (sync) { return throttleMethods.Contains(fullName.Trim()); } } } }