com.dallaway.sloppy
Class Bottleneck
java.lang.Object
|
+--com.dallaway.sloppy.Bottleneck
- public class Bottleneck
- extends java.lang.Object
Mechanism to work out a delay before sending data between client and server.
We make use of a staic hash of Usage objects to record the amount of data
sent between a client and a server. The usage is keyed by client_id (such
as IP address).
We need to do this because a browser may request multiple files at the same
time, and we want to limit overall bandwidth, not just the bandwidth
used on each request.
|
Constructor Summary |
Bottleneck(java.lang.String client_id,
double bpm)
Construct a new bottleneck for a give client |
|
Method Summary |
void |
mark()
Mark a data event. |
long |
restrict(int bytes_read)
Compute the amount of time to sleep for to keep the client's bandwidth
usage inside the BPM measure |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Bottleneck
public Bottleneck(java.lang.String client_id,
double bpm)
- Construct a new bottleneck for a give client
- Parameters:
client_id - A way to idnetify a clientbpm - Bytes per millisecond
mark
public void mark()
- Mark a data event. E.g., client sending data or server sending data.
Call this after every receive of data to keep the BPS computation fresh.
restrict
public long restrict(int bytes_read)
- Compute the amount of time to sleep for to keep the client's bandwidth
usage inside the BPM measure
- Returns:
- sleep Milliseconds to sleep for; may be -ve indicating no sleep required