From 90929ab5d7a7c2c1ed7eeda4205d77e54b266b29 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sat, 28 Aug 2010 02:14:09 +0000 Subject: [PATCH] Fix for reconnection issue in Project X. When clients disconnect, we need to reset the throttle state. When they reconnect, we need to resend the message rate. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6136 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/client/Client.java | 3 ++ .../presents/server/PresentsSession.java | 34 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/java/com/threerings/presents/client/Client.java b/src/java/com/threerings/presents/client/Client.java index a269dbb9f..1ea67f418 100644 --- a/src/java/com/threerings/presents/client/Client.java +++ b/src/java/com/threerings/presents/client/Client.java @@ -829,6 +829,9 @@ public class Client _tickInterval = null; } + // restore the default message throttle + _outThrottle = new Throttle(DEFAULT_MSGS_PER_SECOND, 1000L); + // we know that prior to the call to this method, the observers were notified with // CLIENT_DID_LOGOFF; that may not have been invoked yet, so we don't want to clear out our // communicator reference immediately; instead we queue up a runnable unit to do so to diff --git a/src/java/com/threerings/presents/server/PresentsSession.java b/src/java/com/threerings/presents/server/PresentsSession.java index 3a47c7388..993485667 100644 --- a/src/java/com/threerings/presents/server/PresentsSession.java +++ b/src/java/com/threerings/presents/server/PresentsSession.java @@ -200,11 +200,11 @@ public class PresentsSession @EventThread public void setIncomingMessageThrottle (int messagesPerSec) { - synchronized(_pendingThrottles) { - _pendingThrottles.add(messagesPerSec); + // store and post update immediately if connected + _messagesPerSec = messagesPerSec; + if (getConnection() != null) { + sendThrottleUpdate(); } - postMessage(new UpdateThrottleMessage(messagesPerSec)); - // when we get a ThrottleUpdatedMessage from the client, we'll apply the new throttle } /** @@ -536,9 +536,26 @@ public class PresentsSession // send off a bootstrap notification immediately as we've already got our client object sendBootstrap(); + // resend the throttle update if non-default + if (_messagesPerSec != Client.DEFAULT_MSGS_PER_SECOND) { + sendThrottleUpdate(); + } + log.info("Session resumed " + this + "."); } + /** + * Sends the throttle update to the client. + */ + protected void sendThrottleUpdate () + { + synchronized(_pendingThrottles) { + _pendingThrottles.add(_messagesPerSec); + } + postMessage(new UpdateThrottleMessage(_messagesPerSec)); + // when we get a ThrottleUpdatedMessage from the client, we'll apply the new throttle + } + /** * Queues up a runnable on the object manager thread where we can safely end the session. */ @@ -741,6 +758,12 @@ public class PresentsSession // clear out our connection reference setConnection(null); + // reset the throttle state in case the client reconnects + _throttle = createIncomingMessageThrottle(); + synchronized (_pendingThrottles) { + _pendingThrottles.clear(); + } + // if we are being closed after the omgr has shutdown, then just stop here; the whole world // is about to come to a screeching halt anyway if (_omgr.isRunning()) { @@ -1138,6 +1161,9 @@ public class PresentsSession * session. */ protected int _connectTime; + /** The configured throttle setting (resent to reconnecting clients). */ + protected int _messagesPerSec = Client.DEFAULT_MSGS_PER_SECOND; + /** Prevent the client from sending too many messages too frequently. */ protected Throttle _throttle = createIncomingMessageThrottle();