public class VersionedValueList<T> extends Object
The current and prior version are held for lock-less read access in a transient variable.
The list relies on transient as well as a read-lock to guard against concurrent modification. However a read lock is only taken when a list of old versions must be updated.
When a high watermark is reached, the list on write access removes old versions up to the number of milliseconds compared to current write timestamp.
If an older version is requested then held by the list, the list can either throw an exception or return the current value.
Constructor and Description |
---|
VersionedValueList(String name,
int initialVersion,
T initialValue,
long timestamp,
long millisecondLifetimeOldVersions,
Lock readLock,
int highWatermark,
boolean errorWhenNotFound)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
Object |
addValue(int version,
T value,
long timestamp)
Add a value and version to the list, returning the prior value of the variable.
|
protected CurrentValue<T> |
getCurrentAndPriorValue()
Returns the current and prior version.
|
String |
getName()
Returns the name of the value stored.
|
protected ArrayList<VersionedValue<T>> |
getOlderVersions()
Returns the list of old versions, for testing purposes.
|
T |
getVersion(int versionAndOlder)
Retrieve a value for the given version or older then then given version.
|
String |
toString() |
public VersionedValueList(String name, int initialVersion, T initialValue, long timestamp, long millisecondLifetimeOldVersions, Lock readLock, int highWatermark, boolean errorWhenNotFound)
name
- variable nameinitialVersion
- first version numberinitialValue
- first valuetimestamp
- timestamp of first versionmillisecondLifetimeOldVersions
- number of milliseconds after which older versions get expired and removedreadLock
- for coordinating update to old versionshighWatermark
- when the number of old versions reached high watermark, the list inspects size on every writeerrorWhenNotFound
- true if an exception should be throw if the requested version cannot be found,
or false if the engine should log a warningpublic String getName()
public T getVersion(int versionAndOlder)
The implementaton only locks the read lock if an older version the the prior version is requested.
versionAndOlder
- the version we are looking forpublic Object addValue(int version, T value, long timestamp)
version
- for the value to addvalue
- to addtimestamp
- the time associated with the versionprotected CurrentValue<T> getCurrentAndPriorValue()
protected ArrayList<VersionedValue<T>> getOlderVersions()