public class SimpleConnectionThrottler extends java.lang.Object implements ConnectionThrottler
This throttler simply throttles the rate by checking to see if the rate is above the rate limit, and if it is, sleep occurs so that the rate is decreased (since rate is calculated as data transferred over a period of time). The throttling algorithm is to simply sleep and wait for the next checkup. Sleep interval will actually double each time a checkup occurs and the rate is above the limit. Sleep interval will get reset once rate goes below the limit. The problem with this throttler is that if the remote client is sending at an extremely high speed, you will get a massively long interval which may not be what you want.
Also make sure that you don't use this for global throttling. This class is not multi-thread safe and must not be used as a such (ie. controlling throttling limited to a global transfer rate averaged across all the uploads).
| Constructor and Description |
|---|
SimpleConnectionThrottler(int bps_in)
Constructor that accepts the rate limit in KBytes/sec.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getBPS() |
void |
setBPS(int bps_in) |
void |
throttle(ConnectionModel cmodel)
Throttles the data transfer rate based on the information provided by
the connection model.
|
public SimpleConnectionThrottler(int bps_in)
public void throttle(ConnectionModel cmodel)
ConnectionThrottlerthrottle in interface ConnectionThrottlerpublic int getBPS()
public void setBPS(int bps_in)
Copyright © 2001-2005 Echomine. All Rights Reserved.