org.omus.data
Class CounterField
java.lang.Object
|
+--org.omus.data.DataField
|
+--org.omus.data.CounterField
- All Implemented Interfaces:
- java.lang.Cloneable, java.io.Serializable
- public class CounterField
- extends DataField
A special class for synchronizing int values. This is the only subclass of DataField
that is not just a Java class corresponding to an ActionScript datatype. It makes it
possible to modify int values relative to their current value and thus avoid any
synchronization issues that might occur if different clients modify the int value
of a group property concurrently.
An example: Let's assume you created a Flash client that shows a basket and each
user in the group can put any amount of apples into the basket and take any amount
out of it. If two users put an apple into that basket concurrrently and both clients
add 1 to the current number of apples and then send the new total value to the server,
only one of the two apples gets added to the group property on the server side. If a
property is configured to be a counter, the setValue method of the client
side PropertySet object changes the value relative to the current value. This way the
server receives two "add 1 apple" commands and thus both apples are added to the basket.
In other words: If "foo" is the name of a property configured as a counter, then
setValue("foo",-4) called in PropertySet in the client means:
"subtract 4 from the current value" and only the relative change is submitted to the server.
- See Also:
- Serialized Form
|
Constructor Summary |
CounterField(java.lang.String n,
int v)
Creates a new CounterField with the specified name and initial value. |
|
Method Summary |
void |
accept(FieldVisitor fv)
Accepts a visitor. |
void |
add(int dif)
Adds the specified value to the int value of this CounterField. |
int |
get()
Returns the current value of this CounterField. |
void |
reset()
Resets the value of this CounterField to the initial value. |
void |
set(int newValue)
Sets the value of this CounterField to the specified value. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
CounterField
public CounterField(java.lang.String n,
int v)
- Creates a new CounterField with the specified name and initial value.
get
public int get()
- Returns the current value of this CounterField.
set
public void set(int newValue)
- Sets the value of this CounterField to the specified value.
reset
public void reset()
- Resets the value of this CounterField to the initial value.
add
public void add(int dif)
- Adds the specified value to the int value of this CounterField. Negative values are permitted.
accept
public void accept(FieldVisitor fv)
- Description copied from class:
DataField
- Accepts a visitor. The visitor pattern is useful if you want to extend
the functionality of all DataFields without modifying their API.
- Overrides:
accept in class DataField
toString
public java.lang.String toString()
- Overrides:
toString in class java.lang.Object