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
This commit is contained in:
Andrzej Kapolka
2010-08-28 02:14:09 +00:00
parent 9bdf1f8ef1
commit 90929ab5d7
2 changed files with 33 additions and 4 deletions
@@ -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
@@ -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();