fix the Ice 404 and production 247,143,675,456 percent complete bugs; get bittorrent fully working

This commit is contained in:
Elizabeth Fong
2006-08-17 12:44:15 +00:00
parent ed118c0ffa
commit a98376a2f7
2 changed files with 37 additions and 6 deletions
@@ -20,6 +20,17 @@ public class HTTPDownloader extends Downloader
super(resources, obs);
}
/**
* A method of instantiating a downloader to take over the job partway.
*/
public HTTPDownloader (List<Resource> resources, Observer obs,
long totalSize)
{
super(resources, obs);
_totalSize = totalSize;
_start = System.currentTimeMillis();
}
/**
* Issues a HEAD request for the specified resource and notes the
* amount of data we will be downloading to account for it.
@@ -54,7 +54,7 @@ public class TorrentDownloader extends Downloader
SnarkShutdown stopper = _stoppermap.get(rsrc);
stopper.run();
Runtime.getRuntime().removeShutdownHook(stopper);
_fallback = new HTTPDownloader(_resources, _obs);
fallback();
if (_metaDownload && rsrc.getPath().equals("full")) {
length = 0;
} else {
@@ -87,19 +87,39 @@ public class TorrentDownloader extends Downloader
long now = System.currentTimeMillis();
if ((now - _lastUpdate) >= UPDATE_DELAY) {
_currentSize = snark.coordinator.getDownloaded();
if (_currentSize < SIZE_THRESHOLD &&
(now - _start) >= TIME_THRESHOLD) {
if ((_currentSize < SIZE_THRESHOLD &&
(now - _start) >= TIME_THRESHOLD) ||
(_currentSize == 0 &&
(now - _start) >= TIME_THRESHOLD / 4)) {
Log.info("Torrenting too slow, falling back to HTTP.");
// The download isn't going as planned, abort;
snarkStopper.run();
Runtime.getRuntime().removeShutdownHook(snarkStopper);
_fallback = new HTTPDownloader(_resources, _obs);
_fallback.doDownload(rsrc);
snarkStopper = null;
_stoppermap.remove(rsrc);
if (_metaDownload) {
_metaDownload = false;
}
fallback();
return;
}
}
updateObserver();
}
if (snarkStopper != null) {
snarkStopper.run();
Runtime.getRuntime().removeShutdownHook(snarkStopper);
_stoppermap.remove(rsrc);
}
}
/**
* If torrent downloading either bugs out or is too slow, switch to a
* different method by creating the fallback downloader.
*/
protected void fallback ()
{
_fallback = new HTTPDownloader(_resources, _obs, _totalSize);
}
/** Keeps a mapping of resource names to torrent downloaders */