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();