Package | com.threerings.util |
Class | public class Throttle |
For example:
protected Throttle _throttle = new Throttle(5, 60000L); public void performOp () throws UnavailableException { if (_throttle.throttleOp()) { throw new UnavailableException(); } // perform operation }
Property | Defined by | ||
---|---|---|---|
_oldestOp : int | Throttle | ||
_ops : Array | Throttle | ||
_period : int | Throttle |
Method | Defined by | ||
---|---|---|---|
Throttle(operations:int, period:int)
Constructs a new throttle instance that will allow the specified number of operations to
proceed within the specified period (the period is measured in milliseconds).
| Throttle | ||
getLatestOperation():int
Returns the timestamp of the most recently recorded operation.
| Throttle | ||
noteOp(timeStamp:int):void
Note that an operation occurred at the specified timestamp.
| Throttle | ||
opsToString():String
For debugging, includes the age of all operations.
| Throttle | ||
reinit(operations:int, period:int):void
Updates the number of operations for this throttle to a new maximum, retaining the current
history of operations if the limit is being increased and truncating the newest operations
if the limit is decreased.
| Throttle | ||
throttleOp():Boolean
Registers an attempt at an operation and returns false if the operation should be performed
or true if it should be throttled (meaning N operations have already been performed in the
last M seconds).
| Throttle | ||
throttleOpAt(timeStamp:int):Boolean
Registers an attempt at an operation and returns false if the operation should be performed
or true if it should be throttled (meaning N operations have already been performed in the
last M seconds).
| Throttle | ||
toString():String
| Throttle | ||
wouldThrottle(timeStamp:int):Boolean
Check to see if we would throttle an operation occuring at the specified timestamp.
| Throttle |
_oldestOp | property |
protected var _oldestOp:int
_ops | property |
protected var _ops:Array
_period | property |
protected var _period:int
Throttle | () | constructor |
public function Throttle(operations:int, period:int)
Constructs a new throttle instance that will allow the specified number of operations to proceed within the specified period (the period is measured in milliseconds).
As operations and period define a ratio, use the smallest value possible for
operations
as an array is created to track the time at which each operation was
performed (e.g. use 6 ops per 10 seconds rather than 60 ops per 100 seconds if
possible). However, note that you may not always want to reduce the ratio as much as
possible if you wish to allow bursts of operations up to some large value.
Parameters
operations:int |
|
period:int |
getLatestOperation | () | method |
public function getLatestOperation():int
Returns the timestamp of the most recently recorded operation.
Returnsint |
noteOp | () | method |
public function noteOp(timeStamp:int):void
Note that an operation occurred at the specified timestamp. This method should be used with {
ParameterstimeStamp:int |
opsToString | () | method |
public function opsToString():String
For debugging, includes the age of all operations.
ReturnsString |
reinit | () | method |
public function reinit(operations:int, period:int):void
Updates the number of operations for this throttle to a new maximum, retaining the current history of operations if the limit is being increased and truncating the newest operations if the limit is decreased.
Parametersoperations:int — the new maximum number of operations.
|
|
period:int — the new period (in milliseconds).
|
throttleOp | () | method |
public function throttleOp():Boolean
Registers an attempt at an operation and returns false if the operation should be performed or true if it should be throttled (meaning N operations have already been performed in the last M seconds).
ReturnsBoolean — true if the throttle is activated, false if the operation can proceed.
|
throttleOpAt | () | method |
public function throttleOpAt(timeStamp:int):Boolean
Registers an attempt at an operation and returns false if the operation should be performed or true if it should be throttled (meaning N operations have already been performed in the last M seconds).
ParameterstimeStamp:int — the timestamp at which this operation is being attempted.
|
Boolean — true if the throttle is activated, false if the operation can proceed.
|
toString | () | method |
public function toString():String
Returns
String |
wouldThrottle | () | method |
public function wouldThrottle(timeStamp:int):Boolean
Check to see if we would throttle an operation occuring at the specified timestamp. Typically used in conjunction with {
ParameterstimeStamp:int |
Boolean |