com.espertech.esper.epl.variable
Class VersionedValueList<T>

java.lang.Object
  extended by com.espertech.esper.epl.variable.VersionedValueList<T>

public class VersionedValueList<T>
extends java.lang.Object

A self-cleaning list of versioned-values.

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 Summary
VersionedValueList(java.lang.String name, int initialVersion, T initialValue, long timestamp, long millisecondLifetimeOldVersions, java.util.concurrent.locks.Lock readLock, int highWatermark, boolean errorWhenNotFound)
          Ctor.
 
Method Summary
 java.lang.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.
 java.lang.String getName()
          Returns the name of the value stored.
protected  java.util.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.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VersionedValueList

public VersionedValueList(java.lang.String name,
                          int initialVersion,
                          T initialValue,
                          long timestamp,
                          long millisecondLifetimeOldVersions,
                          java.util.concurrent.locks.Lock readLock,
                          int highWatermark,
                          boolean errorWhenNotFound)
Ctor.

Parameters:
name - variable name
initialVersion - first version number
initialValue - first value
timestamp - timestamp of first version
millisecondLifetimeOldVersions - number of milliseconds after which older versions get expired and removed
readLock - for coordinating update to old versions
highWatermark - when the number of old versions reached high watermark, the list inspects size on every write
errorWhenNotFound - true if an exception should be throw if the requested version cannot be found, or false if the engine should log a warning
Method Detail

getName

public java.lang.String getName()
Returns the name of the value stored.

Returns:
value name

getVersion

public T getVersion(int versionAndOlder)
Retrieve a value for the given version or older then then given version.

The implementaton only locks the read lock if an older version the the prior version is requested.

Parameters:
versionAndOlder - the version we are looking for
Returns:
value for the version or the next older version, ignoring newer versions

addValue

public java.lang.Object addValue(int version,
                                 T value,
                                 long timestamp)
Add a value and version to the list, returning the prior value of the variable.

Parameters:
version - for the value to add
value - to add
timestamp - the time associated with the version
Returns:
prior value

getCurrentAndPriorValue

protected CurrentValue<T> getCurrentAndPriorValue()
Returns the current and prior version.

Returns:
value

getOlderVersions

protected java.util.ArrayList<VersionedValue<T>> getOlderVersions()
Returns the list of old versions, for testing purposes.

Returns:
list of versions older then current and prior version

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

© 2006-2015 EsperTech Inc.
All rights reserved.
Visit us at espertech.com