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:
@@ -20,7 +20,7 @@ public interface EZGameService extends InvocationService
|
||||
*/
|
||||
public void setProperty (
|
||||
Client client, String propName, Object value, int index,
|
||||
InvocationListener listener);
|
||||
boolean testAndSet, InvocationListener listener);
|
||||
|
||||
/**
|
||||
* Request to end the turn, possibly futzing the next turn holder unless
|
||||
|
||||
@@ -61,22 +61,34 @@ public class GameObjectImpl
|
||||
// from EZGame
|
||||
public void set (String propName, Object value)
|
||||
{
|
||||
set(propName, value, -1);
|
||||
set(propName, value, -1, false);
|
||||
}
|
||||
|
||||
// from EZGame
|
||||
public void set (String propName, Object value, boolean testAndSet)
|
||||
{
|
||||
set(propName, value, -1, testAndSet);
|
||||
}
|
||||
|
||||
// from EZGame
|
||||
public void set (String propName, Object value, int index)
|
||||
{
|
||||
set(propName, value, index, false);
|
||||
}
|
||||
|
||||
// from EZGame
|
||||
public void set (String propName, Object value, int index, boolean testAndSet)
|
||||
{
|
||||
validatePropertyChange(propName, value, -1);
|
||||
|
||||
Object encoded = EZObjectMarshaller.encode(value);
|
||||
Object reconstituted = EZObjectMarshaller.decode(encoded);
|
||||
_ezObj.ezGameService.setProperty(
|
||||
_ctx.getClient(), propName, encoded, index,
|
||||
_ctx.getClient(), propName, encoded, index, testAndSet,
|
||||
createLoggingListener("setProperty"));
|
||||
|
||||
// set it immediately in the game object
|
||||
_ezObj.applyPropertySet(propName, reconstituted, index);
|
||||
_ezObj.applyPropertySet(propName, reconstituted, index, testAndSet);
|
||||
}
|
||||
|
||||
// from EZGame
|
||||
|
||||
Reference in New Issue
Block a user