Changed some things around so that we can do operations that may require

a round trip to the database after a user has changed user objects:
the ClientResolutionListener will get a ResultListener that it should
call when its all done.

Hopefully this doesn't break anything in bang or gardens...


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3766 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2005-11-18 02:32:26 +00:00
parent 709c2d94bf
commit 1673cf0865
@@ -28,6 +28,7 @@ import java.util.Iterator;
import com.samskivert.util.HashIntMap; import com.samskivert.util.HashIntMap;
import com.samskivert.util.Throttle; import com.samskivert.util.Throttle;
import com.samskivert.util.ResultListener;
import com.threerings.util.Name; import com.threerings.util.Name;
import com.threerings.presents.Log; import com.threerings.presents.Log;
@@ -82,8 +83,13 @@ public class PresentsClient
/** Called when the new client object has been resolved and the /** Called when the new client object has been resolved and the
* new client object reported to the client, but the old one has * new client object reported to the client, but the old one has
* not yet been destroyed. Any events delivered on this callback * not yet been destroyed. Any events delivered on this callback
* to the old client object will be delivered. */ * to the old client object will be delivered.
public void changeReported (ClientObject newObj); *
* @param rl when this method is finished with its business and
* the old client object can be destroyed, the result listener
* should be called.
* */
public void changeReported (ClientObject newObji, ResultListener rl);
/** Called when the user change is completed, the old client /** Called when the user change is completed, the old client
* object is destroyed and all updates are committed. */ * object is destroyed and all updates are committed. */
@@ -184,7 +190,9 @@ public class PresentsClient
public void setUsername (Name username, final UserChangeListener ucl) public void setUsername (Name username, final UserChangeListener ucl)
{ {
ClientResolutionListener clr = new ClientResolutionListener() { ClientResolutionListener clr = new ClientResolutionListener() {
public void clientResolved (Name username, ClientObject clobj) { public void clientResolved (final Name username,
final ClientObject clobj)
{
// if they old client object is gone by now, they ended // if they old client object is gone by now, they ended
// their session while we were switching, so freak out // their session while we were switching, so freak out
if (_clobj == null) { if (_clobj == null) {
@@ -208,9 +216,25 @@ public class PresentsClient
// let the caller know that we've got some new business // let the caller know that we've got some new business
if (ucl != null) { if (ucl != null) {
ucl.changeReported(clobj); ucl.changeReported(clobj, new ResultListener() {
} public void requestCompleted (Object result) {
finishResolved(username, clobj);
}
public void requestFailed (Exception cause) {
finishResolved(username, clobj);
}
});
} else {
finishResolved(username, clobj);
}
}
/**
* Finish the final phase of the switch.
*/
protected void finishResolved (Name username, ClientObject clobj)
{
// release our old client object; this will destroy it // release our old client object; this will destroy it
_cmgr.releaseClientObject(_username); _cmgr.releaseClientObject(_username);