wire things so both patches and full installs try bittorrent first

This commit is contained in:
Elizabeth Fong
2006-07-16 09:49:54 +00:00
parent 7f5384629e
commit ae36f9138d
4 changed files with 79 additions and 16 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
-injars lib/jRegistryKey.jar(!META-INF/*) -injars lib/jRegistryKey.jar(!META-INF/*)
-injars lib/samskivert.jar(!META-INF/*,!**/velocity/**,!**/xml/**) -injars lib/samskivert.jar(!META-INF/*,!**/velocity/**,!**/xml/**)
-injars lib/commons-io.jar(!META-INF/*) -injars lib/commons-io.jar(!META-INF/*)
# -injars lib/snark.jar(!META-INF/*) -injars lib/snark.jar(!META-INF/*)
-libraryjars <java.home>/lib/rt.jar -libraryjars <java.home>/lib/rt.jar
-dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclasses
@@ -181,6 +181,18 @@ public class Application
return _resources; return _resources;
} }
/**
* Returns a list of all the {@link Resource} objects used by
* this application.
*/
public List<Resource> getAllResources ()
{
List<Resource> allResources = new ArrayList<Resource>();
allResources.addAll(getCodeResources());
allResources.addAll(getActiveResources());
return allResources;
}
/** /**
* Returns a list of all auxiliary resource groups defined by the * Returns a list of all auxiliary resource groups defined by the
* application. An auxiliary resource group is a collection of resource * application. An auxiliary resource group is a collection of resource
@@ -266,6 +278,24 @@ public class Application
} }
} }
/**
* Returns a resource that can be used to download an archive containing
* all files belonging to the application.
*/
public Resource getFullResource ()
{
String file = "full";
try {
URL remote = new URL(createVAppBase(_targetVersion), file);
return new Resource(file, remote, getLocalPath(file), false);
} catch (Exception e) {
Log.warning("Failed to create full resource path [file=" + file +
", appbase=" + _appbase + ", tvers=" + _targetVersion +
", error=" + e + "].");
return null;
}
}
/** /**
* Instructs the application to parse its <code>getdown.txt</code> * Instructs the application to parse its <code>getdown.txt</code>
* configuration and prepare itself for operation. The application * configuration and prepare itself for operation. The application
@@ -757,10 +787,8 @@ public class Application
*/ */
public List<Resource> verifyResources (ProgressObserver obs) public List<Resource> verifyResources (ProgressObserver obs)
{ {
ArrayList<Resource> rsrcs = new ArrayList<Resource>(); List<Resource> rsrcs = getAllResources();
ArrayList<Resource> failures = new ArrayList<Resource>(); List<Resource> failures = new ArrayList<Resource>();
rsrcs.addAll(getCodeResources());
rsrcs.addAll(getActiveResources());
// total up the file size of the resources to validate // total up the file size of the resources to validate
long totalSize = 0L; long totalSize = 0L;
@@ -806,8 +834,7 @@ public class Application
*/ */
public void clearValidationMarkers () public void clearValidationMarkers ()
{ {
clearValidationMarkers(getCodeResources().iterator()); clearValidationMarkers(getAllResources().iterator());
clearValidationMarkers(getActiveResources().iterator());
} }
/** /**
@@ -504,13 +504,18 @@ public abstract class Getdown extends Thread
} }
}; };
// Torrent downloading is disabled by default until the kinks are out
Downloader dl; Downloader dl;
// if (false) { if (resources.equals(_app.getAllResources())) {
// dl = new TorrentDownloader(resources, obs); ArrayList<Resource> full = new ArrayList<Resource>();
// } else { full.add(_app.getFullResource());
full.addAll(resources);
dl = new TorrentDownloader(full, obs);
} else if (resources.size() == 1 &&
resources.get(0).getPath().startsWith("patch")) {
dl = new TorrentDownloader(resources, obs);
} else {
dl = new HTTPDownloader(resources, obs); dl = new HTTPDownloader(resources, obs);
// } }
dl.start(); dl.start();
// now wait for it to complete // now wait for it to complete
@@ -27,6 +27,10 @@ public class TorrentDownloader extends Downloader
Runtime.getRuntime().addShutdownHook(snarkStopper); Runtime.getRuntime().addShutdownHook(snarkStopper);
_torrentmap.put(resource, snark); _torrentmap.put(resource, snark);
_stoppermap.put(resource, snarkStopper); _stoppermap.put(resource, snarkStopper);
if (resource.getPath().equals("full")) {
_metaDownload = true;
break;
}
} }
} }
@@ -34,6 +38,12 @@ public class TorrentDownloader extends Downloader
protected long checkSize(Resource rsrc) protected long checkSize(Resource rsrc)
throws IOException throws IOException
{ {
if (_metaDownload && !rsrc.getPath().equals("full")) {
return 0;
}
if (_fallback != null) {
return _fallback.checkSize(rsrc);
}
Snark snark = _torrentmap.get(rsrc); Snark snark = _torrentmap.get(rsrc);
long length = -1; long length = -1;
try { try {
@@ -41,9 +51,16 @@ public class TorrentDownloader extends Downloader
length = snark.meta.getTotalLength(); length = snark.meta.getTotalLength();
} catch (IOException ioe) { } catch (IOException ioe) {
Log.warning("Bittorrent failed, falling back to HTTP"); Log.warning("Bittorrent failed, falling back to HTTP");
_stoppermap.get(rsrc).run(); SnarkShutdown stopper = _stoppermap.get(rsrc);
stopper.run();
Runtime.getRuntime().removeShutdownHook(stopper);
_fallback = new HTTPDownloader(_resources, _obs); _fallback = new HTTPDownloader(_resources, _obs);
length = _fallback.checkSize(rsrc); if (_metaDownload && rsrc.getPath().equals("full")) {
length = 0;
} else {
length = _fallback.checkSize(rsrc);
}
_metaDownload = false;
} }
return length; return length;
} }
@@ -52,10 +69,17 @@ public class TorrentDownloader extends Downloader
protected void doDownload(Resource rsrc) protected void doDownload(Resource rsrc)
throws IOException throws IOException
{ {
if (_fallback != null) { if (_metaDownload && !rsrc.getPath().equals("full")) {
_fallback.doDownload(rsrc);
return; return;
} }
if (_fallback != null) {
if (rsrc.getPath().equals("full")) {
return;
} else {
_fallback.doDownload(rsrc);
return;
}
}
Snark snark = _torrentmap.get(rsrc); Snark snark = _torrentmap.get(rsrc);
SnarkShutdown snarkStopper = _stoppermap.get(rsrc); SnarkShutdown snarkStopper = _stoppermap.get(rsrc);
snark.collectPieces(); snark.collectPieces();
@@ -67,6 +91,7 @@ public class TorrentDownloader extends Downloader
(now - _start) >= TIME_THRESHOLD) { (now - _start) >= TIME_THRESHOLD) {
// The download isn't going as planned, abort; // The download isn't going as planned, abort;
snarkStopper.run(); snarkStopper.run();
Runtime.getRuntime().removeShutdownHook(snarkStopper);
_fallback = new HTTPDownloader(_resources, _obs); _fallback = new HTTPDownloader(_resources, _obs);
_fallback.doDownload(rsrc); _fallback.doDownload(rsrc);
return; return;
@@ -91,6 +116,12 @@ public class TorrentDownloader extends Downloader
/** The length of time before we check for adequate progress*/ /** The length of time before we check for adequate progress*/
protected static final long TIME_THRESHOLD = 60 * 1000l; protected static final long TIME_THRESHOLD = 60 * 1000l;
/**
* Whether we are downloading an artificially-generated metafile
* representing all of the {@link Resource}s at the end of the file.
*/
protected boolean _metaDownload = false;
/** /**
* The minimum amount of data that must be downloaded within the * The minimum amount of data that must be downloaded within the
* initial period in order to continue using BitTorrent * initial period in order to continue using BitTorrent