Don't declare a pending moveTo request to be stale until at least a minute

has gone by. This prevents us from getting shafted by double clicks.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1456 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-06-14 00:57:49 +00:00
parent 541eb01446
commit b9000bf08c
2 changed files with 59 additions and 20 deletions
@@ -1,5 +1,5 @@
//
// $Id: LocationDirector.java,v 1.20 2002/05/26 02:24:46 mdb Exp $
// $Id: LocationDirector.java,v 1.21 2002/06/14 00:57:48 mdb Exp $
package com.threerings.crowd.client;
@@ -107,15 +107,20 @@ public class LocationDirector
// complain if we're over-writing a pending request
if (_pendingPlaceId != -1) {
Log.warning("We appear to have a moveTo request outstanding " +
"[ppid=" + _pendingPlaceId +
", npid=" + placeId + "].");
// but we're going to fall through and do it anyway because
// refusing to switch rooms at this point will inevitably
// result in some strange bug causing a move request to be
// dropped by the server and the client that did it to be
// totally hosed because they can no longer move to new
// locations because they still have an outstanding request
// if the pending request has been outstanding more than a
// minute, go ahead and let this new one through in an attempt
// to recover from dropped moveTo requests
if (checkRepeatMove()) {
Log.warning("Refusing moveTo; We have a request outstanding " +
"[ppid=" + _pendingPlaceId +
", npid=" + placeId + "].");
return;
} else {
Log.warning("Overriding stale moveTo request " +
"[ppid=" + _pendingPlaceId +
", npid=" + placeId + "].");
}
}
// make a note of our pending place id
@@ -183,6 +188,9 @@ public class LocationDirector
// keep track of our previous place id
_previousPlaceId = _placeId;
// clear out our last request time
_lastRequestTime = 0;
// do some cleaning up in case we were previously in a place
didLeavePlace();
@@ -248,10 +256,29 @@ public class LocationDirector
*/
public void failedToMoveTo (int placeId, String reason)
{
// clear out our last request time
_lastRequestTime = 0;
// let our observers know what's up
notifyFailure(placeId, reason);
}
/**
* Called to test and set a time stamp that we use to determine if a
* pending moveTo request is stale.
*/
public boolean checkRepeatMove ()
{
long now = System.currentTimeMillis();
if (now - _lastRequestTime < STALE_REQUEST_DURATION) {
return true;
} else {
_lastRequestTime = now;
return false;
}
}
// documentation inherited from interface
public void clientDidLogon (Client client)
{
@@ -456,6 +483,9 @@ public class LocationDirector
/** The oid of the place we previously occupied. */
protected int _previousPlaceId = -1;
/** The last time we requested a move to. */
protected long _lastRequestTime;
/** The entity that deals when we fail to subscribe to a place
* object. */
protected FailureHandler _failureHandler;
@@ -467,4 +497,8 @@ public class LocationDirector
return true;
}
};
/** We require that a moveTo request be outstanding for one minute
* before it is declared to be stale. */
protected static final long STALE_REQUEST_DURATION = 60L * 1000L;
}
@@ -1,5 +1,5 @@
//
// $Id: SceneDirector.java,v 1.15 2002/05/26 02:35:02 mdb Exp $
// $Id: SceneDirector.java,v 1.16 2002/06/14 00:57:49 mdb Exp $
package com.threerings.whirled.client;
@@ -129,15 +129,20 @@ public class SceneDirector
// complain if we're over-writing a pending request
if (_pendingSceneId != -1) {
Log.warning("We appear to have a moveTo request outstanding " +
"[psid=" + _pendingSceneId +
", nsid=" + sceneId + "].");
// but we're going to fall through and do it anyway because
// refusing to switch scenes at this point will inevitably
// result in some strange bug causing a move request to be
// dropped by the server and the client that did it to be
// totally hosed because they can no longer move to new scenes
// because they still have an outstanding request
// if the pending request has been outstanding more than a
// minute, go ahead and let this new one through in an attempt
// to recover from dropped moveTo requests
if (_locdir.checkRepeatMove()) {
Log.warning("Refusing moveTo; We have a request outstanding " +
"[psid=" + _pendingSceneId +
", nsid=" + sceneId + "].");
return false;
} else {
Log.warning("Overriding stale moveTo request " +
"[psid=" + _pendingSceneId +
", nsid=" + sceneId + "].");
}
}
// load up the pending scene so that we can communicate it's most