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); 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 * Issues a HEAD request for the specified resource and notes the
* amount of data we will be downloading to account for it. * 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); SnarkShutdown stopper = _stoppermap.get(rsrc);
stopper.run(); stopper.run();
Runtime.getRuntime().removeShutdownHook(stopper); Runtime.getRuntime().removeShutdownHook(stopper);
_fallback = new HTTPDownloader(_resources, _obs); fallback();
if (_metaDownload && rsrc.getPath().equals("full")) { if (_metaDownload && rsrc.getPath().equals("full")) {
length = 0; length = 0;
} else { } else {
@@ -87,19 +87,39 @@ public class TorrentDownloader extends Downloader
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if ((now - _lastUpdate) >= UPDATE_DELAY) { if ((now - _lastUpdate) >= UPDATE_DELAY) {
_currentSize = snark.coordinator.getDownloaded(); _currentSize = snark.coordinator.getDownloaded();
if (_currentSize < SIZE_THRESHOLD && if ((_currentSize < SIZE_THRESHOLD &&
(now - _start) >= TIME_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; // The download isn't going as planned, abort;
snarkStopper.run(); snarkStopper.run();
Runtime.getRuntime().removeShutdownHook(snarkStopper); Runtime.getRuntime().removeShutdownHook(snarkStopper);
_fallback = new HTTPDownloader(_resources, _obs); snarkStopper = null;
_fallback.doDownload(rsrc); _stoppermap.remove(rsrc);
if (_metaDownload) {
_metaDownload = false;
}
fallback();
return; return;
} }
} }
updateObserver(); updateObserver();
} }
snarkStopper.run(); 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 */ /** Keeps a mapping of resource names to torrent downloaders */