LimeWire Consolidated API

com.limegroup.gnutella
Interface DownloadManager

All Superinterfaces:
BandwidthTracker, ListenerSupport<DownloadManagerEvent>, LWSIntegrationServicesDelegate, PushedSocketHandler, SaveLocationManager
All Known Implementing Classes:
DownloadManagerImpl

public interface DownloadManager
extends BandwidthTracker, SaveLocationManager, LWSIntegrationServicesDelegate, PushedSocketHandler, ListenerSupport<DownloadManagerEvent>

The list of all downloads in progress. DownloadManager has a fixed number of download slots given by the MAX_SIM_DOWNLOADS property. It is responsible for starting downloads and scheduling and queueing them as needed. This class is thread safe.

As with other classes in this package, a DownloadManager instance may not be used until initialize(..) is called. The arguments to this are not passed in to the constructor in case there are circular dependencies.

DownloadManager provides ways to serialize download state to disk. Reads are initiated by RouterService, since we have to wait until the GUI is initiated. Writes are initiated by this, since we need to be notified of completed downloads. Downloads in the COULDNT_DOWNLOAD state are not serialized.


Method Summary
 boolean acceptPushedSocket(String file, int index, byte[] clientGUID, Socket socket)
          Accept the newly-connected push socket The given file, index & clientGUID were identified during the push.
 void addNewDownloader(CoreDownloader downloader)
          Adds a new downloader that this will manager.
 void bumpPriority(Downloader downl, boolean up, int amt)
          Bumps the priority of an inactive download either up or down by an amount (if amt==0, bump to start/end of list).
 boolean conflicts(URN urn, long fileSize, File... fileName)
          Returns true if there already is a download with the same urn.
 boolean contains(Downloader downloader)
          Returns true if the given downloader is in either the waiting or active lists.
 Downloader download(DownloadInformation info, long now)
          Downloads an InNetwork update, using the info from the DownloadInformation.
 Downloader download(File incompleteFile)
          Starts a resume download for the given incomplete file.
 Downloader download(MagnetOptions magnet, boolean overwrite, File saveDir, String fileName)
          Creates a new MAGNET downloader.
 Downloader download(RemoteFileDesc[] files, List<? extends RemoteFileDesc> alts, GUID queryGUID, boolean overwrite, File saveDir, String fileName)
          Tries to "smart download" any of the given files.
 Downloader downloadFromMozilla(MozillaDownload listener)
          Creates a Downloader wrapping the MozillaDownloadListener.
 Downloader downloadFromStore(RemoteFileDesc rfd, boolean overwrite, File saveDir, String fileName)
          Creates a new LimeWire Store (LWS) download.
 int downloadsInProgress()
           
 Downloader downloadTorrent(BTMetaInfo info, boolean overwrite)
          Downloads the given torrent specified by the meta info object.
 Downloader downloadTorrent(File torrentFile, boolean overwrite)
          Opens the torrent for the specified file, and begins the torrent download.
 Downloader downloadTorrent(URI torrentURI, boolean overwrite)
          Downloads the torrent file from the specified URI then begins the torrent download as a seperate item.
 Iterable<CoreDownloader> getAllDownloaders()
           
 float getAverageBandwidth()
          returns the summed average of the downloads
 Downloader getDownloaderForIncompleteFile(File file)
          Returns the active or waiting downloader that uses or will use file as incomplete file.
 Downloader getDownloaderForURN(URN sha1)
           
 IncompleteFileManager getIncompleteFileManager()
          Returns the IncompleteFileManager used by this DownloadManager and all ManagedDownloaders.
 float getLastMeasuredBandwidth()
          Returns the measured bandwidth as calculated from the last getMeasuredBandwidth() call.
 float getMeasuredBandwidth()
          Returns the total upload throughput, i.e., the sum over all uploads.
 int getNumActiveDownloads()
          Inner network traffic and downloads from the LWS don't count towards overall download activity.
 int getNumIndividualDownloaders()
           
 int getNumWaitingDownloads()
           
 void handleQueryReply(QueryReply qr, Address address)
          Adds all responses (and alternates) in qr to any downloaders, if appropriate.
 boolean hasInNetworkDownload()
          Determines if an 'In Network' download exists in either active or waiting.
 boolean isActivelyDownloading(URN urn)
          Returns whether or not we are actively downloading this file.
 boolean isGuidForQueryDownloading(GUID guid)
           
 boolean isIncomplete(URN urn)
          Determines if the given URN has an incomplete file.
 boolean isSavedDownloadsLoaded()
          True if saved downloads have been loaded from disk.
 boolean isSaveLocationTaken(File candidateFile)
          Returns true if there already is a download that is or will be saving to this file location.
 void killDownloadersNotListed(Collection<? extends DownloadInformation> updates)
          Kills all in-network downloaders that are not present in the list of DownloadInformations
 void loadSavedDownloadsAndScheduleWriting()
          Performs the slow, low-priority initialization tasks: reading in snapshots and scheduling snapshot checkpointing.
 void measureBandwidth()
          Calls measureBandwidth on each uploader.
 void remove(CoreDownloader downloader, boolean completed)
          Removes downloader entirely from the list of current downloads.
 void sendQuery(QueryRequest query)
          Attempts to send the given requery to provide the given downloader with more sources to download.
 void start()
          Initializes this manager.
 void writeSnapshot()
          Writes a snapshot of all downloaders in this and all incomplete files to the file named DOWNLOAD_SNAPSHOT_FILE.
 
Methods inherited from interface com.limegroup.gnutella.downloader.LWSIntegrationServicesDelegate
visitDownloads
 
Methods inherited from interface org.limewire.listener.ListenerSupport
addListener, removeListener
 

Method Detail

addNewDownloader

void addNewDownloader(CoreDownloader downloader)
Adds a new downloader that this will manager.


start

void start()
Initializes this manager. This method must be called before any other methods are used.


loadSavedDownloadsAndScheduleWriting

void loadSavedDownloadsAndScheduleWriting()
Performs the slow, low-priority initialization tasks: reading in snapshots and scheduling snapshot checkpointing.


isSavedDownloadsLoaded

boolean isSavedDownloadsLoaded()
True if saved downloads have been loaded from disk.


hasInNetworkDownload

boolean hasInNetworkDownload()
Determines if an 'In Network' download exists in either active or waiting.


killDownloadersNotListed

void killDownloadersNotListed(Collection<? extends DownloadInformation> updates)
Kills all in-network downloaders that are not present in the list of DownloadInformations

Parameters:
updates - a current set of DownloadInformation that we are downloading in-network.

acceptPushedSocket

boolean acceptPushedSocket(String file,
                           int index,
                           byte[] clientGUID,
                           Socket socket)
Description copied from interface: PushedSocketHandler
Accept the newly-connected push socket The given file, index & clientGUID were identified during the push.

Specified by:
acceptPushedSocket in interface PushedSocketHandler
Returns:
true if the handler accepted the socket

isIncomplete

boolean isIncomplete(URN urn)
Determines if the given URN has an incomplete file.


isActivelyDownloading

boolean isActivelyDownloading(URN urn)
Returns whether or not we are actively downloading this file.


getIncompleteFileManager

IncompleteFileManager getIncompleteFileManager()
Returns the IncompleteFileManager used by this DownloadManager and all ManagedDownloaders.


downloadsInProgress

int downloadsInProgress()

getNumIndividualDownloaders

int getNumIndividualDownloaders()

getNumActiveDownloads

int getNumActiveDownloads()
Inner network traffic and downloads from the LWS don't count towards overall download activity.


getNumWaitingDownloads

int getNumWaitingDownloads()

getDownloaderForURN

Downloader getDownloaderForURN(URN sha1)

getDownloaderForIncompleteFile

Downloader getDownloaderForIncompleteFile(File file)
Returns the active or waiting downloader that uses or will use file as incomplete file.

Parameters:
file - the incomplete file candidate
Returns:
null if no downloader for the file is found

isGuidForQueryDownloading

boolean isGuidForQueryDownloading(GUID guid)

download

Downloader download(RemoteFileDesc[] files,
                    List<? extends RemoteFileDesc> alts,
                    GUID queryGUID,
                    boolean overwrite,
                    File saveDir,
                    String fileName)
                    throws SaveLocationException
Tries to "smart download" any of the given files.

If any of the files already being downloaded (or queued for downloaded) has the same temporary name as any of the files in 'files', throws AlreadyDownloadingException. Note, however, that this doesn't guarantee that a successfully downloaded file can be moved to the library.

If overwrite==false, then if any of the files already exists in the download directory, FileExistsException is thrown and no files are modified. If overwrite==true, the files may be overwritten.

Otherwise returns a Downloader that allows you to stop and resume this download. The DownloadCallback will also be notified of this download, so the return value can usually be ignored. The download begins immediately, unless it is queued. It stops after any of the files succeeds.

Parameters:
files - a group of "similar" files to smart download
alts - a List of secondary RFDs to use for other sources
queryGUID - the guid of the query that resulted in the RFDs being downloaded.
overwrite - whether or not to overwrite the file
saveDir - can be null, then the default save directory is used
fileName - can be null, then the first filename of one of element of files is taken.
Throws:
SaveLocationException - when there was an error setting the location of the final download destination.

download

Downloader download(MagnetOptions magnet,
                    boolean overwrite,
                    File saveDir,
                    String fileName)
                    throws IllegalArgumentException,
                           SaveLocationException
Creates a new MAGNET downloader. Immediately tries to download from defaultURL, if specified. If that fails, or if defaultURL does not provide alternate locations, issues a requery with textQuery and urn, as provided. (At least one must be non-null.) If filename is specified, it will be used as the name of the complete file; otherwise it will be taken from any search results or guessed from defaultURLs.

Parameters:
magnet - information fields extracted from a magnet link
overwrite - whether or not to overwrite the file
saveDir - can be null, then the default save directory is used
filename - the final file name, or null if unknown
Throws:
IllegalArgumentException - if the magnet is not downloadable
SaveLocationException - if the file can't save because of an existing file in the location

downloadFromStore

Downloader downloadFromStore(RemoteFileDesc rfd,
                             boolean overwrite,
                             File saveDir,
                             String fileName)
                             throws IllegalArgumentException,
                                    SaveLocationException
Creates a new LimeWire Store (LWS) download. Store downloads are handled in a similar fashion as MAGNET links except there are no alternative locations. filename should always be specified since we have complete control over META-DATA for these downloads, it will be used as the name of the complete file. Unlike all other downloads performed here, saveDir is a unique directory specified in the options menu under Store Downloads.

Parameters:
rfd - Descriptor describing the download from the store including URN
overwrite - true if same file names should be overwritten; false if the user should be notified of a duplicate file name
saveDir - directory to save the completed file into
fileName - name of the completed file
Returns:
a download object
Throws:
IllegalArgumentException - if there is a bad argument
SaveLocationException - if the file is already downloading

download

Downloader download(File incompleteFile)
                    throws CantResumeException,
                           SaveLocationException
Starts a resume download for the given incomplete file.

Throws:
CantResumeException - incompleteFile is not a valid incomplete file
SaveLocationException - if the file can't save because of an existing file in the location

download

Downloader download(DownloadInformation info,
                    long now)
                    throws SaveLocationException
Downloads an InNetwork update, using the info from the DownloadInformation.

Throws:
SaveLocationException

downloadTorrent

Downloader downloadTorrent(URI torrentURI,
                           boolean overwrite)
                           throws SaveLocationException
Downloads the torrent file from the specified URI then begins the torrent download as a seperate item.

Throws:
SaveLocationException

downloadTorrent

Downloader downloadTorrent(File torrentFile,
                           boolean overwrite)
                           throws SaveLocationException
Opens the torrent for the specified file, and begins the torrent download.

Throws:
SaveLocationException

downloadTorrent

Downloader downloadTorrent(BTMetaInfo info,
                           boolean overwrite)
                           throws SaveLocationException
Downloads the given torrent specified by the meta info object.

Throws:
SaveLocationException

conflicts

boolean conflicts(URN urn,
                  long fileSize,
                  File... fileName)
Returns true if there already is a download with the same urn.

Parameters:
urn - may be null, then a check based on the fileName and the fileSize is performed
Returns:
true if there is a conflict

isSaveLocationTaken

boolean isSaveLocationTaken(File candidateFile)
Returns true if there already is a download that is or will be saving to this file location.

Specified by:
isSaveLocationTaken in interface SaveLocationManager
Parameters:
candidateFile - the final file location.
Returns:
true if the file's save location is already used

handleQueryReply

void handleQueryReply(QueryReply qr,
                      Address address)
Adds all responses (and alternates) in qr to any downloaders, if appropriate.

Parameters:
address - can be null, otherwise overrides the address information in qr

remove

void remove(CoreDownloader downloader,
            boolean completed)
Removes downloader entirely from the list of current downloads. Notifies callback of the change in status. If completed is true, finishes the download completely. Otherwise, puts the download back in the waiting list to be finished later.


bumpPriority

void bumpPriority(Downloader downl,
                  boolean up,
                  int amt)
Bumps the priority of an inactive download either up or down by an amount (if amt==0, bump to start/end of list).


sendQuery

void sendQuery(QueryRequest query)
Attempts to send the given requery to provide the given downloader with more sources to download. May not actually send the requery if it doing so would exceed the maximum requery rate.

Parameters:
query - the requery to send, which should have a marked GUID. Queries are subjected to global rate limiting if and only if they have marked requery GUIDs.

measureBandwidth

void measureBandwidth()
Calls measureBandwidth on each uploader.

Specified by:
measureBandwidth in interface BandwidthTracker

getMeasuredBandwidth

float getMeasuredBandwidth()
Returns the total upload throughput, i.e., the sum over all uploads.

Specified by:
getMeasuredBandwidth in interface BandwidthTracker

getAverageBandwidth

float getAverageBandwidth()
returns the summed average of the downloads

Specified by:
getAverageBandwidth in interface BandwidthTracker

getLastMeasuredBandwidth

float getLastMeasuredBandwidth()
Returns the measured bandwidth as calculated from the last getMeasuredBandwidth() call.


getAllDownloaders

Iterable<CoreDownloader> getAllDownloaders()

writeSnapshot

void writeSnapshot()
Writes a snapshot of all downloaders in this and all incomplete files to the file named DOWNLOAD_SNAPSHOT_FILE. It is safe to call this method at any time for checkpointing purposes. Returns true if and only if the file was successfully written.


downloadFromMozilla

Downloader downloadFromMozilla(MozillaDownload listener)
Creates a Downloader wrapping the MozillaDownloadListener. Adds capability to track status of mozilla download.


contains

boolean contains(Downloader downloader)
Returns true if the given downloader is in either the waiting or active lists.


LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.