option to discard slow proxies April 04, 2012 01:17PM |
Registered: 12 years ago Posts: 4 |
Implemented as a dirty hack - works great April 10, 2012 09:17AM |
Registered: 12 years ago Posts: 4 |
Index: src/cz/vity/freerapid/core/tasks/SpeedRegulator.java =================================================================== --- src/cz/vity/freerapid/core/tasks/SpeedRegulator.java (revision 3534) +++ src/cz/vity/freerapid/core/tasks/SpeedRegulator.java (working copy) @@ -2,10 +2,12 @@ import cz.vity.freerapid.core.AppPrefs; import cz.vity.freerapid.core.UserProp; +import cz.vity.freerapid.gui.managers.ManagerDirector; import cz.vity.freerapid.model.DownloadFile; import cz.vity.freerapid.plugins.webclient.DownloadState; import javax.swing.event.SwingPropertyChangeSupport; +import java.awt.datatransfer.StringSelection; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.*; @@ -17,6 +19,9 @@ * @author Vity */ public final class SpeedRegulator implements PropertyChangeListener { +// My modifications: + private ManagerDirector manager_director; + private final static Logger logger = Logger.getLogger(SpeedRegulator.class.getName()); private Mapdownloading = new Hashtable (10); @@ -29,8 +34,10 @@ private volatile long speed; private volatile float averageSpeed; +// My modifications: + public SpeedRegulator( ManagerDirector d ) { + this.manager_director = d; - public SpeedRegulator() { timer = null; speed = 0; averageSpeed = 0; @@ -180,7 +187,9 @@ file.setTokensLimit(Integer.MAX_VALUE); file.setSpeed(0); file.setAverageSpeed(0); - downloading.put(file, new DownloadFileInfo(task)); +// My modifications: + downloading.put(file, new DownloadFileInfo( task, manager_director )); + if (timer == null) { timer = new Timer("SpeedRegulatorTimer"); timer.schedule(new TimerTask() { @@ -226,6 +235,10 @@ } private static class DownloadFileInfo { +// My modifications: +DownloadFile debug_exception; + private ManagerDirector manager_director; + private volatile long counter = 0; private long lastSize = 0; private int noDataTimeOut = 0; //XXX seconds to timeout @@ -243,7 +256,10 @@ private float averageSpeed; private long downloadedStart; - DownloadFileInfo(DownloadTask task) { +// My modifications: + DownloadFileInfo( DownloadTask task, ManagerDirector director ) { + this.manager_director = director; + this.task = task; this.file = task.getDownloadFile(); downloadedStart = this.file.getDownloaded(); @@ -275,8 +291,43 @@ // task.setSpeed(speed); file.setSpeed(speed); - if (speed == 0) { - if (++noDataTimeOut >= NO_DATA_TIMEOUT_LIMIT) { //X seconds with no data +// My modifications: + final long Default_Min_Seconds_Before_Proxy_Avg_Chk = 20 * 1000; // * 1000 = seconds + final float Default_Proxy_Min_Avg_Speed_Before_50_Percent = 15 * 1024.0F; // * 1024 = kb/s + final float Default_Proxy_Min_Avg_Speed_Before_80_Percent = 10 * 1024.0F; + final float Default_Proxy_Min_Avg_Speed_Before_90_Percent = 5 * 1024.0F; + final float Default_Proxy_Min_Avg_Speed_After_90_Percent = 1 * 1024.0F; + long current_time = System.currentTimeMillis(); + String proxy_url = file.getConnectionSettings().getProxyURL(); + boolean proxy_is_too_slow = false; + double percent_complete = ( 100.0 / file.getFileSize() ) * lastSize; + if( ( ( current_time - startTime ) > Default_Min_Seconds_Before_Proxy_Avg_Chk ) ) { + if( ( percent_complete < 50.0 ) && + ( file.getAverageSpeed() < Default_Proxy_Min_Avg_Speed_Before_50_Percent ) ) { +//String s = debug_exception.getFileName(); + proxy_is_too_slow = true; + } else if( ( percent_complete < 80.0 ) && + ( file.getAverageSpeed() < Default_Proxy_Min_Avg_Speed_Before_80_Percent ) ) { +//String s = debug_exception.getFileName(); + proxy_is_too_slow = true; + } else if( ( percent_complete < 90.0 ) && + ( file.getAverageSpeed() < Default_Proxy_Min_Avg_Speed_Before_90_Percent ) ) { +//String s = debug_exception.getFileName(); + proxy_is_too_slow = true; + } else if( file.getAverageSpeed() < Default_Proxy_Min_Avg_Speed_After_90_Percent ) { +//String s = debug_exception.getFileName(); + proxy_is_too_slow = true; + } + if( proxy_is_too_slow ) { +//String s = debug_exception.getFileName(); + manager_director.getClientManager().setConnectionEnabled( file.getConnectionSettings(), false ); + manager_director.getClientManager().updateProxyConnectionList(); + } + } + if( speed == 0 || proxy_is_too_slow ) { + if( proxy_is_too_slow || ( ++noDataTimeOut >= NO_DATA_TIMEOUT_LIMIT ) ) { //X seconds with no data + if( proxy_is_too_slow ) + noDataTimeOut = 0; logger.info("Cancelling download - no downloaded data during " + NO_DATA_TIMEOUT_LIMIT + " seconds"); averageSpeed = 0; task.setConnectionTimeOut(true); Index: src/cz/vity/freerapid/gui/managers/ClientManager.java =================================================================== --- src/cz/vity/freerapid/gui/managers/ClientManager.java (revision 3534) +++ src/cz/vity/freerapid/gui/managers/ClientManager.java (working copy) @@ -35,7 +35,8 @@ private final List availableConnections = new ArrayList (2); private Stack workingClientsPool = new Stack (); private static final String PROXY_LIST_DEFAULT_PATH = new File(Utils.getAppPath(), "proxy.list").getAbsolutePath(); - public static final int MAX_DOWNLOADING = 10; +// My modifications: + public static final int MAX_DOWNLOADING = 100000; private ConnectionSettings defaultConnectionSettings = new ConnectionSettings(); Index: src/cz/vity/freerapid/gui/managers/ManagerDirector.java =================================================================== --- src/cz/vity/freerapid/gui/managers/ManagerDirector.java (revision 3534) +++ src/cz/vity/freerapid/gui/managers/ManagerDirector.java (working copy) @@ -240,7 +240,8 @@ public SpeedRegulator getSpeedRegulator() { if (speedRegulator == null) { - speedRegulator = new SpeedRegulator(); +// My modifications: + speedRegulator = new SpeedRegulator( this ); } return speedRegulator; }
Re: option to discard slow proxies October 31, 2012 06:02PM |
Registered: 12 years ago Posts: 7 |