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:
@@ -829,6 +829,9 @@ public class Client
|
|||||||
_tickInterval = null;
|
_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
|
// 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
|
// 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
|
// communicator reference immediately; instead we queue up a runnable unit to do so to
|
||||||
|
|||||||
@@ -200,11 +200,11 @@ public class PresentsSession
|
|||||||
@EventThread
|
@EventThread
|
||||||
public void setIncomingMessageThrottle (int messagesPerSec)
|
public void setIncomingMessageThrottle (int messagesPerSec)
|
||||||
{
|
{
|
||||||
synchronized(_pendingThrottles) {
|
// store and post update immediately if connected
|
||||||
_pendingThrottles.add(messagesPerSec);
|
_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
|
// send off a bootstrap notification immediately as we've already got our client object
|
||||||
sendBootstrap();
|
sendBootstrap();
|
||||||
|
|
||||||
|
// resend the throttle update if non-default
|
||||||
|
if (_messagesPerSec != Client.DEFAULT_MSGS_PER_SECOND) {
|
||||||
|
sendThrottleUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Session resumed " + this + ".");
|
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.
|
* 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
|
// clear out our connection reference
|
||||||
setConnection(null);
|
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
|
// 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
|
// is about to come to a screeching halt anyway
|
||||||
if (_omgr.isRunning()) {
|
if (_omgr.isRunning()) {
|
||||||
@@ -1138,6 +1161,9 @@ public class PresentsSession
|
|||||||
* session. */
|
* session. */
|
||||||
protected int _connectTime;
|
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. */
|
/** Prevent the client from sending too many messages too frequently. */
|
||||||
protected Throttle _throttle = createIncomingMessageThrottle();
|
protected Throttle _throttle = createIncomingMessageThrottle();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user