From 301c1cbe4d63d202e472b788fa178975ca5a0428 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 21 Jul 2005 20:23:37 +0000 Subject: [PATCH] Dispatch the notification that the client failed to logon after we are completely cleaned up so that an immediate attempt to logon using a different configuration will not fail due to the client thinking it's still logged on from the previous failed attempt. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3658 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/client/Client.java | 20 ++++++++++++++----- .../presents/client/Communicator.java | 11 +++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/java/com/threerings/presents/client/Client.java b/src/java/com/threerings/presents/client/Client.java index 28f3540e7..091217446 100644 --- a/src/java/com/threerings/presents/client/Client.java +++ b/src/java/com/threerings/presents/client/Client.java @@ -431,7 +431,7 @@ public class Client public void standaloneLogoff () { notifyObservers(CLIENT_DID_LOGOFF, null); - cleanup(); + cleanup(null); } /** @@ -529,7 +529,7 @@ public class Client _clobj = clobj; // let the client know that logon has now fully succeeded - notifyObservers(Client.CLIENT_DID_LOGON, null); + notifyObservers(CLIENT_DID_LOGON, null); } /** @@ -539,7 +539,7 @@ public class Client protected void getClientObjectFailed (Exception cause) { // pass the buck onto the listeners - notifyObservers(Client.CLIENT_FAILED_TO_LOGON, cause); + notifyObservers(CLIENT_FAILED_TO_LOGON, cause); } /** @@ -552,7 +552,7 @@ public class Client _cloid = _clobj.getOid(); // report to our observers - notifyObservers(Client.CLIENT_OBJECT_CHANGED, null); + notifyObservers(CLIENT_OBJECT_CHANGED, null); } boolean notifyObservers (int code, Exception cause) @@ -582,7 +582,7 @@ public class Client } } - synchronized void cleanup () + synchronized void cleanup (final Exception logonError) { // we know that prior to the call to this method, the observers // were notified with CLIENT_DID_LOGOFF; that may not have been @@ -598,8 +598,18 @@ public class Client _clobj = null; _cloid = -1; _standalone = false; + // and let our invocation director know we're logged off _invdir.cleanup(); + + // if we were cleaned up due to a failure to logon, we can + // report the logon error now that the communicator is + // cleaned up; this allows a logon failure listener to + // immediately try another logon (hopefully with something + // changed like the server or port) + if (logonError != null) { + notifyObservers(CLIENT_FAILED_TO_LOGON, logonError); + } } }); } diff --git a/src/java/com/threerings/presents/client/Communicator.java b/src/java/com/threerings/presents/client/Communicator.java index b68076a70..cecda4ff2 100644 --- a/src/java/com/threerings/presents/client/Communicator.java +++ b/src/java/com/threerings/presents/client/Communicator.java @@ -246,7 +246,7 @@ public class Communicator closeChannel(); // let the client know when we finally go away - _client.cleanup(); + _client.cleanup(_logonError); } Log.debug("Reader thread exited."); @@ -271,7 +271,7 @@ public class Communicator // let the client know when we finally go away if (_reader == null) { - _client.cleanup(); + _client.cleanup(_logonError); } } @@ -413,9 +413,9 @@ public class Communicator } catch (Exception e) { Log.debug("Logon failed: " + e); Log.logStackTrace(e); - // let the observers know that we've failed - _client.notifyObservers(Client.CLIENT_FAILED_TO_LOGON, e); - // and terminate our communicator thread + // once we're shutdown we'll report this error + _logonError = e; + // terminate our communicator thread shutdown(); } } @@ -602,6 +602,7 @@ public class Communicator protected Queue _msgq = new Queue(); protected long _lastWrite; + protected Exception _logonError; /** We use this to frame our upstream messages. */ protected FramingOutputStream _fout;