For EZ property sets, added a setter that performs an "atomic" test-and-set:

it's atomic in the sense that a single server event will test the variable, 
and only set it if the previous value was null (i.e. didn't exist). 
This allows for a level of elementary synchronization between the clients.

The new function on EZGameControl is:
  _gameCtrl.testAndSet (propertyName, newValue[, index])

I hoped to generalize this to test against arbitrary values, but that's 
significantly harder, since properties accept numerous types as values,
and those can have different representations on the client and the server.
So it remains a check against null until we need to generalize it. :)





git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@193 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Robert Zubeck
2007-02-15 21:55:49 +00:00
parent 720a409185
commit bdfcd156ab
17 changed files with 136 additions and 91 deletions
@@ -178,12 +178,12 @@ public class EZGameMarshaller extends InvocationMarshaller
public static const SET_PROPERTY :int = 11;
// from interface EZGameService
public function setProperty (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :InvocationService_InvocationListener) :void
public function setProperty (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :Boolean, arg6 :InvocationService_InvocationListener) :void
{
var listener5 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
listener5.listener = arg5;
var listener6 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
listener6.listener = arg6;
sendRequest(arg1, SET_PROPERTY, [
arg2, arg3, Integer.valueOf(arg4), listener5
arg2, arg3, Integer.valueOf(arg4), langBoolean.valueOf(arg5), listener6
]);
}
@@ -98,26 +98,30 @@ public class EZGameObject extends GameObject
* @return the old value
*/
public function applyPropertySet (
propName :String, value :Object, index :int) :Object
propName :String, value :Object, index :int, testAndSet :Boolean)
:Object
{
var oldValue :Object = _props[propName];
if (index >= 0) {
// set an array element
var arr :Array = (oldValue as Array);
if (arr == null) {
arr = [];
_props[propName] = arr;
if ((testAndSet && oldValue == null) || ! testAndSet)
{
if (index >= 0) {
// set an array element
var arr :Array = (oldValue as Array);
if (arr == null) {
arr = [];
_props[propName] = arr;
}
oldValue = arr[index];
arr[index] = value;
} else if (value != null) {
// normal property set
_props[propName] = value;
} else {
// remove a property
delete _props[propName];
}
oldValue = arr[index];
arr[index] = value;
} else if (value != null) {
// normal property set
_props[propName] = value;
} else {
// remove a property
delete _props[propName];
}
return oldValue;
}
@@ -35,7 +35,7 @@ public class PropertySetEvent extends NamedEvent
override public function applyToObject (target :DObject) :Boolean
{
_oldValue =
EZGameObject(target).applyPropertySet(_name, _data, _index);
EZGameObject(target).applyPropertySet(_name, _data, _index, _testAndSet);
return true;
}
@@ -69,6 +69,7 @@ public class PropertySetEvent extends NamedEvent
super.readObject(ins);
_index = ins.readInt();
_data = EZObjectMarshaller.decode(ins.readObject());
_testAndSet = ins.readBoolean();
}
// from interface Streamable
@@ -77,6 +78,7 @@ public class PropertySetEvent extends NamedEvent
super.writeObject(out);
out.writeInt(_index);
out.writeObject(_data);
out.writeBoolean(_testAndSet);
}
override protected function notifyListener (listener :Object) :void
@@ -99,6 +101,9 @@ public class PropertySetEvent extends NamedEvent
/** The client-side data that is assigned to this property. */
protected var _data :Object;
/** When true, the property will only be set if its previous value was null. */
protected var _testAndSet :Boolean;
/** The old value. */
protected var _oldValue :Object;
}