DownloadStateListener instance will be notified by the Azureus engine for events relating to the torrent download. In the implementation above we start off a daemon thread that prints out the completed percentage of the file to the command line every 10 seconds once downloading starts. We then issue the shutdown of the Azureus engine and exit the application once the download is complete (method
downloadComplete()). As mentioned earlier, the Azureus engine generally runs asynchronously to the rest of the application, so the only way to gather the completed percentage of a download is to continually check (in this case with a daemon thread) the statistics provided by the
When we build and execute the above application we should get something like the following:
C:\SimpleDownloader>java -cp Azureus2.jar;torrent-client.jar client.SimpleStandaloneDownloader http://localhost:8080/torrent-server/download.torrent Attempting to download torrent at : http://localhost:8080/torrent-server/download.torrent Completed download of : http://localhost:8080/torrent-server/download.torrent File stored as : C:\DOCUME~1\jacks\LOCALS~1\Temp\torrentDownload55518torrent Checking.... Downloading.... Download is 61.9 % complete Download is 61.9 % complete Download is 65.9 % complete Download is 75.8 % complete Download is 78.6 % complete Download is 78.7 % complete Download is 82.2 % complete Download is 93.8 % complete Download is 99.8 % complete Finishing Download.... Download is 100.0 % complete Download Complete - Seeding for other users.... Download Completed - Exiting..... Download Stopped.
A More Advanced Example: Regular Distribution of Data Files to a Large Audience
SimpleStandaloneDownloader class is useful for illustrating the basic usage of the Azureus API, it does not add anything to what you can do with any out-of-the-box BitTorrent client. In this section we shall look at implementing a solution for a more real world scenario--the distribution of large data files to numerous client at regular intervals.
The regular distribution of large files has become a core part of many software platforms. Although the actual applications themselves are quite diverse and range from World of Warcraft to Windows XP and the Java Runtime Environment, they all have one thing in common--Automatic Updates.
Following the traditional client-server approach and allowing clients to download these files from a relatively small number of servers can be quite costly in terms of bandwidth and energy requirements. This is especially true if there are a large number of clients that require updates. The traditional client-server approach is also very prone to falling victim to flash crowds (or slashdotting as it is also known) once a new update is made available.
Peer-to-peer networks, by contrast, share the load more evenly amongst the participants and do not suffer from the same problems outlined above. In fact, the more people in the swarm, the better the file will be distributed. In this section we will look at how it is possible to build a solution that distributes regular updates over BitTorrent (as is being done by Blizzard for World of Warcraft) using the Azureus engine.
The server implementation is a combination of the tracker server and the initial seeder that will make the file available to the swarm. It provides administrators with a web interface through that they can upload a new file to be distributed to swarm as well as some useful statistics for monitoring the tracker and initial seeder.
Figure 2. The Tracker/Initial Seeder Management console (Click to enlarge.)