|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.vars.EventVariableValueBuffer
public final class EventVariableValueBuffer
Thread-safe mutable value of a local or global system event variable. This is the mutable version of EventVariableValue as StringBuilder is to String.
The current stats should be collected in instances of this, then converted to EventVariableValue for longer-term storage and/or to return to users.
This is designed to be efficient and quick to mutate.
This class is thread-safe, and methods may be synchronized.
This attempts to conserve memory, at the cost of some CPU time, by attempting to effectively intern() event values. This therefore assumes that all event values are sensibly intern()able, eg immutable and with equals() and hashCode() methods that cover all visible state.
| Nested Class Summary | |
|---|---|
(package private) static class |
EventVariableValueBuffer.Count
Private class to contain an int count value. |
| Field Summary | |
|---|---|
private java.util.Map<java.lang.Object,EventVariableValueBuffer.Count> |
counts
Map from event value to count of events of that value. |
private SimpleVariableDefinition |
def
The (immutable) variable definition; never null. |
private EventVariableValue |
evvCache
Private cache for toEventVariableValue(). |
private long |
intervalNumber
The (immutable) interval number; strictly positive. |
private EventPeriod |
period
The (immutable) event period; never null. |
private static boolean |
REPLACE_ON_UPDATE
If true, replace our data rather than merge on update(). |
private static long |
serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/. |
private int |
totalEventCount
Total event count; non-negative. |
| Constructor Summary | |
|---|---|
EventVariableValueBuffer(SimpleVariableDefinition def,
EventPeriod period,
long intervalNumber)
Construct a single variable value. |
|
| Method Summary | |
|---|---|
void |
addEvent(SimpleVariableValue svv)
Record/add event to the tally. |
private java.lang.Object |
compactValue(boolean shouldIntern,
java.lang.Object value)
Return the compacted form of a value or the original, possibly intern()ing. |
boolean |
equals(java.lang.Object obj)
Equality is based on the definition, period and interval number, but not the event values. |
SimpleVariableDefinition |
getDef()
Get the variable definition; never null. |
long |
getIntervalNumber()
Get the interval number; strictly positive. |
EventPeriod |
getPeriod()
Get the event period; never null. |
int |
getTotalEventCount()
Get the total event count; non-negative. |
int |
hashCode()
The hash is built on a subset of the fields. |
private void |
readObject(java.io.ObjectInputStream ois)
Deserialise. |
EventVariableValue |
toEventVariableValue()
Convert to (immutable) non-authoritative EventVariableValue. |
java.lang.String |
toString()
Generate human-readable summary of state. |
void |
update(EventVariableValue upstream)
Update/merge the value with upstream data. |
void |
validateObject()
Check that the object state is consistent and legal. |
private void |
writeObject(java.io.ObjectOutputStream oos)
Customise how we save state when serialising. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private transient EventVariableValue evvCache
Avoids having to expensively recreate a new evv when nothing has changed.
We do not serialise/persist this redundant state.
private final SimpleVariableDefinition def
private final EventPeriod period
private final long intervalNumber
private int totalEventCount
Mutable; accessed under the instance lock.
private java.util.Map<java.lang.Object,EventVariableValueBuffer.Count> counts
Not thread-safe (access should be protected by other means).
private static final boolean REPLACE_ON_UPDATE
private static final long serialVersionUID
| Constructor Detail |
|---|
public EventVariableValueBuffer(SimpleVariableDefinition def,
EventPeriod period,
long intervalNumber)
throws java.lang.IllegalArgumentException
def - the variable definition; never null and must be an eventperiod - the event period for this sample; never nullintervalNumber - the period number, zero means "all";
non-negative
java.lang.IllegalArgumentException - if the arguments are invalid| Method Detail |
|---|
public EventVariableValue toEventVariableValue()
public SimpleVariableDefinition getDef()
public EventPeriod getPeriod()
public long getIntervalNumber()
public int getTotalEventCount()
public java.lang.String toString()
toString in class java.lang.Objectpublic void addEvent(SimpleVariableValue svv)
The total event count is incremented and if appropriate the value and/or count of occurrences of that value will be incremented.
Note that null values are not recorded in the map, but the totalCount is still incremented.
If the totalEventCount would be about to overflow, then we halve it and halve the count of all extant entries (removing any that become zero).
svv - event to be recorded; must be non-null and of event typepublic void update(EventVariableValue upstream)
We compute an approximate merge, which is assumed to be OK to do at all but the master node since downstream nodes will eventually get overridden with correct authoritative values from upstream.
The approximation consists of increasing the event count to the maximum found in this item and the supplied value, and then adjusting the total event count suitably (allowing for events not stored as values in the map) This may result in a total event count higher than either this or the upstream data.
This should not be used at the very top-level master store to avoid double-counting values, etc.
This may be quite slow.
private java.lang.Object compactValue(boolean shouldIntern,
java.lang.Object value)
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object
private void readObject(java.io.ObjectInputStream ois)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
private void writeObject(java.io.ObjectOutputStream oos)
throws java.io.IOException
java.io.IOException
public void validateObject()
throws java.io.InvalidObjectException
validateObject in interface java.io.ObjectInputValidationjava.io.InvalidObjectException
|
DHD Multimedia Gallery V1.53.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||