Allow client resolution to bail out in an orderly fashion is a disconnection occurs

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5640 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2009-01-22 06:32:14 +00:00
parent 2a1b047159
commit ba600f771d
2 changed files with 26 additions and 2 deletions
@@ -45,6 +45,13 @@ import static com.threerings.presents.Log.log;
*/
public class ClientResolver extends Invoker.Unit
{
/**
* Thrown during resolution if the client disconnects.
*/
public static class ClientDisconnectedException extends Exception
{
}
/**
* Initiailizes this instance.
*
@@ -191,6 +198,17 @@ public class ClientResolver extends Invoker.Unit
}
}
/**
* Throws an exception if the client being resolved is no longer connected.
*/
protected void enforceConnected ()
throws ClientDisconnectedException
{
if (_clmgr.getClient(_username) == null) {
throw new ClientDisconnectedException();
}
}
/** The name of the user whose client object is being resolved. */
protected Name _username;
@@ -206,4 +224,5 @@ public class ClientResolver extends Invoker.Unit
// dependencies
protected @Inject @MainInvoker Invoker _invoker;
protected @Inject RootDObjectManager _omgr;
protected @Inject ClientManager _clmgr;
}
@@ -388,8 +388,13 @@ public class PresentsSession
// from interface ClientResolutionListener
public void resolutionFailed (Name username, Exception reason)
{
// urk; nothing to do but complain and get the f**k out of dodge
log.warning("Unable to resolve client", "username", username, reason);
if (reason instanceof ClientResolver.ClientDisconnectedException) {
log.info("Client disconnected during resolution", "username", username);
} else {
// urk; nothing to do but complain and get the f**k out of dodge
log.warning("Unable to resolve client", "username", username, reason);
}
// end the session now to prevent danglage
endSession();