/// <summary> /// Add a value and version to the list, returning the prior value of the variable. /// </summary> /// <param name="version">for the value to add</param> /// <param name="value">to add</param> /// <param name="timestamp">the time associated with the version</param> /// <returns>prior value</returns> public object AddValue( int version, T value, long timestamp) { if (ExecutionPathDebugLog.IsDebugEnabled && Log.IsDebugEnabled) { Log.Debug( ".addValue Thread " + Thread.CurrentThread.ManagedThreadId + " for '" + Name + "' adding version " + version + " at value " + value); } // push to prior if not already used if (_currentAndPriorValue.PriorVersion.Version == -1) { _currentAndPriorValue = new CurrentValue<T>( new VersionedValue<T>(version, value, timestamp), _currentAndPriorValue.CurrentVersion); return _currentAndPriorValue.PriorVersion.Value; } // add to list var priorVersion = _currentAndPriorValue.PriorVersion; _olderVersions.Add(priorVersion); // check watermarks if (_olderVersions.Count >= _highWatermark) { var expireBefore = timestamp - _millisecondLifetimeOldVersions; while (_olderVersions.Count > 0) { var oldestVersion = _olderVersions[0]; if (oldestVersion.Timestamp <= expireBefore) { _olderVersions.RemoveAt(0); } else { break; } } } _currentAndPriorValue = new CurrentValue<T>( new VersionedValue<T>(version, value, timestamp), _currentAndPriorValue.CurrentVersion); return _currentAndPriorValue.PriorVersion.Value; }
/// <summary>Ctor.</summary> /// <param name="name">variable name</param> /// <param name="initialVersion">first version number</param> /// <param name="initialValue">first value</param> /// <param name="timestamp">timestamp of first version</param> /// <param name="millisecondLifetimeOldVersions"> /// number of milliseconds after which older versions get expired and removed /// </param> /// <param name="readLock">for coordinating Update to old versions</param> /// <param name="highWatermark"> /// when the number of old versions reached high watermark, the list inspects size on every write /// </param> /// <param name="errorWhenNotFound"> /// true if an exception should be throw if the requested version cannot be found, /// or false if the engine should log a warning /// </param> public VersionedValueList( string name, int initialVersion, T initialValue, long timestamp, long millisecondLifetimeOldVersions, ILockable readLock, int highWatermark, bool errorWhenNotFound) { Name = name; _readLock = readLock; _highWatermark = highWatermark; _olderVersions = new List<VersionedValue<T>>(); _errorWhenNotFound = errorWhenNotFound; _millisecondLifetimeOldVersions = millisecondLifetimeOldVersions; _currentAndPriorValue = new CurrentValue<T>( new VersionedValue<T>(initialVersion, initialValue, timestamp), new VersionedValue<T>(-1, null, timestamp)); }