diff --git a/etc/getdown.pro b/etc/getdown.pro index 8108e77..a8fb173 100644 --- a/etc/getdown.pro +++ b/etc/getdown.pro @@ -9,6 +9,7 @@ -injars lib/jRegistryKey.jar(!META-INF/*) -injars lib/samskivert.jar(!META-INF/*,!**/velocity/**,!**/xml/**) -injars lib/commons-io.jar(!META-INF/*) +-injars lib/snark.jar(!META-INF/*) -libraryjars /lib/rt.jar -dontskipnonpubliclibraryclasses diff --git a/lib/LIBS b/lib/LIBS index c4a2782..ff566c1 100644 --- a/lib/LIBS +++ b/lib/LIBS @@ -2,3 +2,4 @@ samskivert.jar ant.jar commons-io.jar javaws.jar +snark.jar diff --git a/src/java/com/threerings/getdown/launcher/Downloader.java b/src/java/com/threerings/getdown/launcher/Downloader.java index 31f3ee4..401eec7 100644 --- a/src/java/com/threerings/getdown/launcher/Downloader.java +++ b/src/java/com/threerings/getdown/launcher/Downloader.java @@ -141,6 +141,9 @@ public abstract class Downloader extends Thread _totalSize += checkSize(rsrc); } + /** + * Performs the protocol-specific portion of checking download size. + */ protected abstract long checkSize (Resource rsrc) throws IOException; /** @@ -162,6 +165,10 @@ public abstract class Downloader extends Thread doDownload(rsrc); } + /** + * Periodically called by the protocol-specific downloaders + * to update their progress. + */ protected void updateObserver () { // notify the observer if it's been sufficiently long @@ -192,7 +199,7 @@ public abstract class Downloader extends Thread /** * Accomplishes the copying of the resource from remote location to - * local location using transport-specific code + * local location using protocol-specific code */ protected abstract void doDownload (Resource rsrc) throws IOException; diff --git a/src/java/com/threerings/getdown/launcher/HTTPDownloader.java b/src/java/com/threerings/getdown/launcher/HTTPDownloader.java index e47d056..ae6986f 100644 --- a/src/java/com/threerings/getdown/launcher/HTTPDownloader.java +++ b/src/java/com/threerings/getdown/launcher/HTTPDownloader.java @@ -10,6 +10,9 @@ import com.samskivert.io.StreamUtil; import com.threerings.getdown.Log; import com.threerings.getdown.data.Resource; +/** + * Implements downloading files over HTTP + */ public class HTTPDownloader extends Downloader { public HTTPDownloader (List resources, Observer obs) @@ -40,6 +43,7 @@ public class HTTPDownloader extends Downloader return ucon.getContentLength(); } + // documentation inherited protected void doDownload (Resource rsrc) throws IOException { diff --git a/src/java/com/threerings/getdown/launcher/TorrentDownloader.java b/src/java/com/threerings/getdown/launcher/TorrentDownloader.java index b090a62..0b7920f 100644 --- a/src/java/com/threerings/getdown/launcher/TorrentDownloader.java +++ b/src/java/com/threerings/getdown/launcher/TorrentDownloader.java @@ -10,6 +10,9 @@ import org.klomp.snark.SnarkShutdown; import com.threerings.getdown.Log; import com.threerings.getdown.data.Resource; +/** + * Implements downloading data using BitTorrent + */ public class TorrentDownloader extends Downloader { public TorrentDownloader (List resources, Observer obs) @@ -24,7 +27,7 @@ public class TorrentDownloader extends Downloader } } - @Override + // documentation inherited protected long checkSize(Resource rsrc) throws IOException { @@ -44,7 +47,7 @@ public class TorrentDownloader extends Downloader return length; } - @Override + // documentation inherited protected void doDownload(Resource rsrc) throws IOException { @@ -75,9 +78,19 @@ public class TorrentDownloader extends Downloader snark.shutdown(); } + /** Keeps a mapping of resource names to torrent downloaders */ protected HashMap _torrentmap = new HashMap(); + + /** If we fail, revert to using this HTTP download transport */ protected HTTPDownloader _fallback = null; + + /** The length of time before we check for adequate progress*/ protected static final long TIME_THRESHOLD = 60 * 1000l; + + /** + * The minimum amount of data that must be downloaded within the + * initial period in order to continue using BitTorrent + */ protected static final long SIZE_THRESHOLD = 4000l; }