com.echomine.net
Class SimpleTransferRateThrottler

java.lang.Object
  extended by com.echomine.net.SimpleTransferRateThrottler
All Implemented Interfaces:
TransferRateThrottler

public class SimpleTransferRateThrottler
extends java.lang.Object
implements TransferRateThrottler

This transfer rate 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 Summary
SimpleTransferRateThrottler(int bps_in)
          Constructor that accepts the rate limit in KBytes/sec.
 
Method Summary
 int getBPS()
           
 void setBPS(int bps_in)
           
 void throttle(FileModel filemodel)
          Throttles the transfer rate based on the information provided by the file model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTransferRateThrottler

public SimpleTransferRateThrottler(int bps_in)
Constructor that accepts the rate limit in KBytes/sec.

Method Detail

throttle

public void throttle(FileModel filemodel)
Description copied from interface: TransferRateThrottler
Throttles the transfer rate based on the information provided by the file model. Most likely you'll be using the calculated transfer rate and do some sort of sleep to slow down the transfer rate.

Specified by:
throttle in interface TransferRateThrottler

getBPS

public int getBPS()

setBPS

public void setBPS(int bps_in)


Copyright © 2001-2005 Echomine. All Rights Reserved.