All of the ActionScript side of adjustable outgoing message rate throttling
except the actual throttling part. Need to think about a good way to do this without blocking the whole client when we hit the throttle. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5428 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -28,6 +28,7 @@ import flash.utils.Timer;
|
||||
|
||||
import com.threerings.util.Log;
|
||||
import com.threerings.util.MethodQueue;
|
||||
import com.threerings.util.Throttle;
|
||||
|
||||
import com.threerings.presents.client.InvocationService_ConfirmListener;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
@@ -41,12 +42,16 @@ import com.threerings.presents.net.BootstrapData;
|
||||
import com.threerings.presents.net.Credentials;
|
||||
import com.threerings.presents.net.PingRequest;
|
||||
import com.threerings.presents.net.PongResponse;
|
||||
import com.threerings.presents.net.ThrottleUpdatedMessage;
|
||||
|
||||
public class Client extends EventDispatcher
|
||||
{
|
||||
/** The default port on which the server listens for client connections. */
|
||||
public static const DEFAULT_SERVER_PORTS :Array = [ 47624 ];
|
||||
|
||||
/** Our default maximum outgoing message rate in messages per second. */
|
||||
public static const DEFAULT_MSGS_PER_SECOND :int = 10;
|
||||
|
||||
private static const log :Log = Log.getLog(Client);
|
||||
|
||||
public function Client (creds :Credentials)
|
||||
@@ -390,6 +395,34 @@ public class Client extends EventDispatcher
|
||||
notifyObservers(ClientEvent.CLIENT_OBJECT_CHANGED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to dispatch a client event to any listeners and return the result of
|
||||
* dispatchEvent.
|
||||
*/
|
||||
public function notifyObservers (evtCode :String, cause :Error = null) :Boolean
|
||||
{
|
||||
return dispatchEvent(new ClientEvent(evtCode, this, cause));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the omgr when we receive a pong packet.
|
||||
*/
|
||||
internal function gotPong (pong :PongResponse) :void
|
||||
{
|
||||
// TODO: compute time delta?
|
||||
}
|
||||
|
||||
internal function setOutgoingMessageThrottle (messagesPerSec :int) :void
|
||||
{
|
||||
_outThrottle.reinit(messagesPerSec, 1000);
|
||||
_comm.postMessage(new ThrottleUpdatedMessage());
|
||||
}
|
||||
|
||||
internal function getOutgoingMessageThrottle () :Throttle
|
||||
{
|
||||
return _outThrottle;
|
||||
}
|
||||
|
||||
internal function cleanup (logonError :Error) :void
|
||||
{
|
||||
// clear out our references
|
||||
@@ -413,24 +446,6 @@ public class Client extends EventDispatcher
|
||||
_switcher = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the omgr when we receive a pong packet.
|
||||
*/
|
||||
public function gotPong (pong :PongResponse) :void
|
||||
{
|
||||
// TODO: compute time delta?
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to dispatch a client event to any listeners
|
||||
* and return the result of dispatchEvent.
|
||||
*/
|
||||
public function notifyObservers (evtCode :String, cause :Error = null)
|
||||
:Boolean
|
||||
{
|
||||
return dispatchEvent(new ClientEvent(evtCode, this, cause));
|
||||
}
|
||||
|
||||
/** The credentials we used to authenticate with the server. */
|
||||
protected var _creds :Credentials;
|
||||
|
||||
@@ -458,9 +473,8 @@ public class Client extends EventDispatcher
|
||||
/** The entity that manages our network communications. */
|
||||
protected var _comm :Communicator;
|
||||
|
||||
/** Our list of client observers. */
|
||||
// protected var _observers :ObserverList =
|
||||
// new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY);
|
||||
/** Our outgoing message throttle. */
|
||||
protected var _outThrottle :Throttle = new Throttle(DEFAULT_MSGS_PER_SECOND, 1000);
|
||||
|
||||
/** The set of bootstrap service groups this client cares about. */
|
||||
protected var _bootGroups :Array = new Array(InvocationCodes.GLOBAL_GROUP);
|
||||
@@ -477,15 +491,5 @@ public class Client extends EventDispatcher
|
||||
/** Used to temporarily track our server switcher so that we can tell when we're logging off
|
||||
* whether or not we're switching servers or actually ending our session. */
|
||||
protected var _switcher :ServerSwitcher;
|
||||
|
||||
// client observer constants
|
||||
/*
|
||||
internal static const CLIENT_DID_LOGON :int = 0;
|
||||
internal static const CLIENT_FAILED_TO_LOGON :int = 1;
|
||||
internal static const CLIENT_OBJECT_CHANGED :int = 2;
|
||||
internal static const CLIENT_CONNECTION_FAILED :int = 3;
|
||||
internal static const CLIENT_WILL_LOGOFF :int = 4;
|
||||
internal static const CLIENT_DID_LOGOFF :int = 5;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.threerings.presents.net.PongResponse;
|
||||
import com.threerings.presents.net.SubscribeRequest;
|
||||
import com.threerings.presents.net.UnsubscribeRequest;
|
||||
import com.threerings.presents.net.UnsubscribeResponse;
|
||||
import com.threerings.presents.net.UpdateThrottleMessage;
|
||||
|
||||
/**
|
||||
* The client distributed object manager manages a set of proxy objects
|
||||
@@ -170,6 +171,9 @@ public class ClientDObjectMgr
|
||||
|
||||
} else if (msg is PongResponse) {
|
||||
_client.gotPong(msg as PongResponse);
|
||||
|
||||
} else if (msg is UpdateThrottleMessage) {
|
||||
_client.setOutgoingMessageThrottle((msg as UpdateThrottleMessage).messagesPerSec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2008 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.net {
|
||||
|
||||
/**
|
||||
* Notifies the server that the client has received its UpdateThrottleMessage.
|
||||
*/
|
||||
public class ThrottleUpdatedMessage extends UpstreamMessage
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2008 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.net {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
|
||||
/**
|
||||
* Notifies the client that its message throttle has been updated.
|
||||
*/
|
||||
public class UpdateThrottleMessage extends DownstreamMessage
|
||||
{
|
||||
/** The number of messages allowed per second. */
|
||||
public var messagesPerSec :int;
|
||||
|
||||
public function UpdateThrottleMessage (messagesPerSec :int = 0)
|
||||
{
|
||||
this.messagesPerSec = messagesPerSec;
|
||||
}
|
||||
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
messagesPerSec = ins.readInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user