|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.vars.SimpleVariableValue
public final class SimpleVariableValue
Immutable value of a simple local or global system variable. This contains the type and value and date-of-change of a system variable.
This is Serializable to enable it to be sent over network connections, persisted, etc.
The types of all legitimate values are immutable, thus preserving the immutability of instances of this class.
This class is not Internable because some fields are ignored by equals(); the value may be worth intern()ing however.
We ensure that the timestamp is unique (and monotonically increasing) in combination with the definition name for this class loader, so that in combination with an originating system ID value it should be possible to recognise and discard duplicate messages reasonably accurately without adding any more data to each message (eg some sort of unique ID which might be bulky and slow to create).
| Field Summary | |
|---|---|
private static java.util.concurrent.ConcurrentMap<java.lang.String,java.util.concurrent.atomic.AtomicLong> |
_timestamps
Shared concurrent map from definition name to last-issued timestamp (null if none yet); never null. |
static java.util.Comparator<SimpleVariableValue> |
compByDef
A simple comparator that sorts by definition (and thus name) alone. |
private SimpleVariableDefinition |
def
The variable definition; never null. |
private java.util.Map<InstanceID,SimpleVariableValue> |
globalMap
An immutable Map from InstanceID keys to SimpleVariableValues each of the same definition and with no global map. |
private static long |
serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/. |
private long |
timestamp
The time at which the value object was constructed; strictly positive. |
static int |
TIMESTAMP_TOLERANCE_MS
Effective tolerance in timestamp value (ms); non-negative. |
private java.lang.Object |
value
The variable value; null or a type allowed by the definition. |
| Constructor Summary | |
|---|---|
|
SimpleVariableValue(SimpleVariableDefinition def,
java.lang.Object value)
Construct a single variable value. |
private |
SimpleVariableValue(SimpleVariableDefinition def,
java.lang.Object value,
java.util.Map<InstanceID,SimpleVariableValue> globalMap,
long timeStamp)
Construct a single variable value. |
| Method Summary | |
|---|---|
private static long |
createUniqueTimestamp(SimpleVariableDefinition def)
Create the timestamp for a new message; strictly positive. |
boolean |
equals(java.lang.Object obj)
Equality is based on the definition (name, type, etc) and value. |
SimpleVariableDefinition |
getDef()
Get the variable definition; never null. |
java.lang.String |
getFullDescription()
Routine to print a full techie-readable description of a variable. |
java.util.Map<InstanceID,SimpleVariableValue> |
getGlobalMap()
Gets immutable Map from InstanceID to SimpleVariableValue; may be null or non-empty. |
long |
getTimestamp()
Get the time at which the value object was constructed. |
java.lang.Object |
getValue()
Get the variable definition; null or a type allowed by the definition. |
int |
hashCode()
The hash is built on a subset of the fields. |
SimpleVariableValue |
put(InstanceID client,
SimpleVariableValue mapEntryValue)
Make a new value identical except for a new/updated globalMap mapping. |
SimpleVariableValue |
put(InstanceID client,
SimpleVariableValue mapEntryValue,
boolean useNewValue)
Make a new value identical except for a new/updated globalMap mapping. |
protected java.lang.Object |
readResolve()
Deserialise: use constructor for validation, defensive copying, etc. |
SimpleVariableValue |
removeAllKeysOlder(long oldestAllowed)
Return instance with all mappings older than specified limit removed. |
private static boolean |
shouldIntern(SimpleVariableDefinition def)
Returns true if we should probably automatically intern() the value. |
java.lang.String |
toString()
Human-readable summary of variable value. |
void |
validateObject()
Check that the object state is consistent and legal. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int TIMESTAMP_TOLERANCE_MS
This allows values to be issued in (efficient) small bursts without pause, and allows for the fact that not all JVMs have a true 1ms clock tick, eg often granularity may be 10ms or 20ms or even more.
A value of 10 to 100 is probably reasonable, though this must remain much smaller than the skew tolerance to avoid confusion.
private static final java.util.concurrent.ConcurrentMap<java.lang.String,java.util.concurrent.atomic.AtomicLong> _timestamps
Limited in size to the number of distinct definitions.
private final SimpleVariableDefinition def
private final java.lang.Object value
private final long timestamp
private final java.util.Map<InstanceID,SimpleVariableValue> globalMap
It must be null for local variables.
For global variables where this is non-null it must contain only keys that are distinct InstanceID values, and only values that are SimpleVariableValues with exactly the same definition and a null globalMap.
Is immutable (if non-null) so that it can be returned directly.
Never an empty Map; null is used in this case.
public static final java.util.Comparator<SimpleVariableValue> compByDef
private static final long serialVersionUID
| Constructor Detail |
|---|
private SimpleVariableValue(SimpleVariableDefinition def,
java.lang.Object value,
java.util.Map<InstanceID,SimpleVariableValue> globalMap,
long timeStamp)
throws java.lang.IllegalArgumentException
This is private because though all parameters are checked we generally only want to add or remove map entries one at a time, and we want to handle timestamp values carefully.
We attempt to intern() the value to economise on memory if we think that it will be worthwhile to so do.
def - the variable definition; never nullvalue - the variable value; null or correct typeglobalMap - if non-null the Map from
InstanceID to SimpleVariableValue;
a private copy is taken in the constructor
and an empty Map is converted to a null
java.lang.IllegalArgumentException - if the arguments are invalid
public SimpleVariableValue(SimpleVariableDefinition def,
java.lang.Object value)
throws java.lang.IllegalArgumentException
def - the variable definition; never nullvalue - the variable value; null or correct type
java.lang.IllegalArgumentException - if the arguments are invalid| Method Detail |
|---|
private static long createUniqueTimestamp(SimpleVariableDefinition def)
This may wait to be able to create a new timestamp.
If the clock is set backwards this may wait a long time.
public SimpleVariableDefinition getDef()
public java.lang.Object getValue()
public long getTimestamp()
public java.util.Map<InstanceID,SimpleVariableValue> getGlobalMap()
Never an empty Map.
private static boolean shouldIntern(SimpleVariableDefinition def)
public java.lang.String toString()
This also makes it easy to use directly in (say) a JSP where if the variable is missing entirely we'll get a benign "null", and to render it simply we don't have to risk calling a method on a possibly null value.
toString in class java.lang.Objectpublic java.lang.String getFullDescription()
This will be a long (single line) of text with values embedded.
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object
public SimpleVariableValue put(InstanceID client,
SimpleVariableValue mapEntryValue)
Both the client and value must be non-null, and the value:
public SimpleVariableValue put(InstanceID client,
SimpleVariableValue mapEntryValue,
boolean useNewValue)
Both the client and value must be non-null, and the value:
useNewValue - if true, the basic value and timestamp
are taken from the new map entry, rather than from thispublic SimpleVariableValue removeAllKeysOlder(long oldestAllowed)
Used for trimming away data from dead systems.
Returns unchanged any instance with a null or empty globalMap, or where all of the keys in the globalMap are in the specified Set. Else returns a new, modified value.
oldestAllowed - any key older than this excluded from the resultprotected java.lang.Object readResolve()
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 | ||||||||