Exemplo n.º 1
0
 public CacheSettingService(IGenericStore <TCacheSetting> store, ICacheManager cacheManager, ILoggerFactory loggerFactory, IAsyncLock asyncLock)
 {
     Store        = store.NotNull(nameof(store));
     CacheManager = cacheManager.NotNull(nameof(cacheManager));
     Logger       = loggerFactory.NotNull(nameof(loggerFactory)).CreateLogger(GetType()).NotNull(nameof(Logger));
     AsyncLock    = asyncLock.NotNull(nameof(asyncLock));
 }
Exemplo n.º 2
0
 protected override async Task OnStartAsync()
 {
     //创建异步锁(内存)
     this.coinLocker = Provider.CreateLock();
     //获得消耗者
     this.machine = await this.Provider.GetAsync(new RemoteAddress("Machine"));
 }
        internal AsyncDictionary(IAsyncLock asyncLock, IDictionary <TKey, TValue> dict)
        {
            Guard.NotNull(asyncLock, nameof(asyncLock));
            Guard.NotNull(dict, nameof(dict));

            this.asyncLock  = asyncLock;
            this.dictionary = dict;
        }
 public DatabaseSearchHistoryService(IGenericStore <IncomingRequest> incomingRequestStore, IGenericStore <OutgoingRequest> outgoingRequestStore,
                                     ICacheSettingService <TCacheSetting> cacheSettingService, ILimitSettingService <TLimitSetting> limitSettingService,
                                     ILoggerFactory loggerFactory, ISystemClock systemClock, IAsyncLock asyncLock)
 {
     IncomingRequestStore = incomingRequestStore.NotNull(nameof(incomingRequestStore));
     OutgoingRequestStore = outgoingRequestStore.NotNull(nameof(outgoingRequestStore));
     CacheSettingService  = cacheSettingService.NotNull(nameof(cacheSettingService));
     LimitSettingService  = limitSettingService.NotNull(nameof(limitSettingService));
     Logger      = loggerFactory.NotNull(nameof(loggerFactory)).CreateLogger(GetType()).NotNull(nameof(Logger));
     SystemClock = systemClock.NotNull(nameof(systemClock));
     AsyncLock   = asyncLock.NotNull(nameof(asyncLock));
 }
Exemplo n.º 5
0
 public async Task <bool> TryAcquire(IAsyncLock asyncLock)
 {
     Assert.True(await asyncLock.AcquireAsync(TimeSpan.FromMilliseconds(500)));
     try
     {
         return(true);
     }
     finally
     {
         asyncLock.Release();
     }
 }
        public IAsyncLock GetOrCreate(string key, IAsyncLock value)
        {
            if (_asyncLockDictionary.TryGetValue(key, out var asyncLock))
            {
                if (!_asyncLockDictionary.TryUpdate(key, value, asyncLock))
                {
                    throw new InvalidOperationException();
                }

                return(value);
            }

            if (!_asyncLockDictionary.TryAdd(key, value))
            {
                throw new InvalidOperationException();
            }

            return(value);
        }
 public AsyncDictionary(IAsyncLock asyncLock) : this(asyncLock, new Dictionary <TKey, TValue>())
 {
 }
Exemplo n.º 8
0
 public Resource(IAsyncLock @lock) => Lock = @lock;
 public GoogleCalendarFactory(IDataStore store, IAsyncLock asyncLock)
 {
     _store     = store;
     _asyncLock = asyncLock;
 }