Methods Summary |
---|
private void | ensureByteBucketMinBurstRate()Make sure the bucket's burst rate is at least MSS-sized,
otherwise it will never allow a full packet's worth of data.
int mss = NetworkManager.getMinMssSize();
if( burst_rate < mss ) { //oops, this won't ever allow a full packet
burst_rate = mss; //so increase the max byte size
}
|
public int | getAvailableByteCount()Get the number of bytes currently available for use.
update_avail_byte_count();
return (int)avail_bytes;
|
public int | getBurstRate()Get the configured burst rate. return burst_rate;
|
public int | getRate()Get the configured fill rate. return rate;
|
public void | setBytesUsed(int bytes_used)Update the bucket with the number of bytes just used.
avail_bytes -= bytes_used;
if( avail_bytes < 0 ) Debug.out( "avail_bytes < 0: " + avail_bytes);
|
public void | setRate(int rate_bytes_per_sec)Set the current fill/guaranteed rate, with a burst rate of 1.2X the given rate.
setRate( rate_bytes_per_sec, rate_bytes_per_sec + (rate_bytes_per_sec/5));
|
public void | setRate(int rate_bytes_per_sec, int burst_rate)Set the current fill/guaranteed rate, along with the burst rate.
if( rate_bytes_per_sec < 0 ) {
Debug.out("rate_bytes_per_sec [" +rate_bytes_per_sec+ "] < 0");
rate_bytes_per_sec = 0;
}
if( burst_rate < rate_bytes_per_sec ) {
Debug.out("burst_rate [" +burst_rate+ "] < rate_bytes_per_sec [" +rate_bytes_per_sec+ "]");
burst_rate = rate_bytes_per_sec;
}
this.rate = rate_bytes_per_sec;
this.burst_rate = burst_rate;
ensureByteBucketMinBurstRate();
|
private void | update_avail_byte_count()
final long now =SystemTime.getCurrentTime();
if (prev_update_time <now) {
avail_bytes +=((now -prev_update_time) * rate) / 1000;
prev_update_time =now;
if( avail_bytes > burst_rate ) avail_bytes = burst_rate;
else if( avail_bytes < 0 ) Debug.out("ERROR: avail_bytes < 0: " + avail_bytes);
}
else if (prev_update_time >now) { //oops, time went backwards
avail_bytes =burst_rate;
prev_update_time =now;
}
|