protected static CountConfig GetCachedObject(CountConfig config) { try { CountConfig.syncObject.EnterUpgradeableReadLock(); CountConfig result; if (CountConfig.ExistingConfig.TryGetValue(config, out result)) { return(result); } try { CountConfig.syncObject.EnterWriteLock(); CountConfig.ExistingConfig.Add(config, config); } finally { if (CountConfig.syncObject.IsWriteLockHeld) { CountConfig.syncObject.ExitWriteLock(); } } } finally { if (CountConfig.syncObject.IsUpgradeableReadLockHeld) { CountConfig.syncObject.ExitUpgradeableReadLock(); } } return(config); }
internal void TimedUpdate() { DateTime dateTime = this.timeProvider(); if (dateTime - this.lastUnpromotedEmptiedTime > this.config.PromotionInterval) { this.unpromotedMeasures.Clear(); this.lastUnpromotedEmptiedTime = dateTime; } CountConfig.CleanupCachedConfig(dateTime, this.config.IdleCachedConfigCleanupInterval); foreach (CountTracker <TEntityType, TCountType> .EntityValue entityValue in this.entities.Values) { entityValue.TimedUpdate(); } this.RemoveEmptyEntities(dateTime); if (this.needsEntityCleanup) { this.RemoveExcessEntitiesPerGroup(dateTime); this.RemoveExcessEntities(dateTime); this.needsEntityCleanup = false; } }
public static RollingCountConfig Create(bool promotable, int minActivityThreshold, TimeSpan timeToLive, TimeSpan idleTimeToLive, bool removable, TimeSpan idleCleanupInterval, TimeSpan windowInterval, TimeSpan windowBucketSize, Func <DateTime> timeProvider) { RollingCountConfig config = new RollingCountConfig(promotable, minActivityThreshold, timeToLive, idleTimeToLive, removable, windowInterval, windowBucketSize, idleCleanupInterval, timeProvider); return((RollingCountConfig)CountConfig.GetCachedObject(config)); }
public bool Equals(CountConfig config) { return(!object.ReferenceEquals(null, config) && (object.ReferenceEquals(this, config) || (this.isPromotable.Equals(config.isPromotable) && this.minActivityThreshold == config.minActivityThreshold && this.timeToLive.Equals(config.timeToLive) && this.idleTimeToLive.Equals(config.idleTimeToLive) && this.isRemovable.Equals(config.isRemovable) && this.idleCleanupInterval.Equals(config.idleCleanupInterval)))); }
public static AbsoluteCountConfig Create(bool promotable, int minActivityThreshold, TimeSpan timeToLive, TimeSpan idleTimeToLive, bool removable, TimeSpan idleCleanupInterval, TimeSpan historyLookbackWindow, Func <DateTime> timeProvider) { AbsoluteCountConfig config = new AbsoluteCountConfig(promotable, minActivityThreshold, timeToLive, idleTimeToLive, removable, idleCleanupInterval, historyLookbackWindow, timeProvider); return((AbsoluteCountConfig)CountConfig.GetCachedObject(config)); }