|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.DownloadManager
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 queing 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.
Field Summary | |
static long |
TIME_BETWEEN_REQUERIES
The global minimum time between any two requeries, in milliseconds. |
Constructor Summary | |
DownloadManager()
|
Method Summary | |
void |
acceptDownload(java.net.Socket socket)
Accepts the given socket for a push download to this host. |
java.lang.String |
conflicts(RemoteFileDesc[] files,
ManagedDownloader dloader)
Returns the name of any of the files in 'files' conflict with any of the downloads in this except for dloader, which may be null. |
Downloader |
download(java.io.File incompleteFile)
Starts a resume download for the given incomplete file. |
Downloader |
download(RemoteFileDesc[] files,
java.util.List alts,
boolean overwrite)
Tries to "smart download" any of the given files. |
Downloader |
download(java.lang.String query,
java.lang.String richQuery,
byte[] guid,
MediaType type)
Starts a "requery download", aka, a "wishlist download". |
Downloader |
download(URN urn,
java.lang.String textQuery,
java.lang.String filename,
java.lang.String[] defaultURL)
Creates a new MAGNET downloader. |
int |
downloadsInProgress()
|
float |
getAverageBandwidth()
returns the summed average of the downloads |
IncompleteFileManager |
getIncompleteFileManager()
Returns the IncompleteFileManager used by this DownloadManager and all ManagedDownloaders. |
float |
getMeasuredBandwidth()
Returns the total upload throughput, i.e., the sum over all uploads. |
int |
getNumActiveDownloads()
|
int |
getNumIndividualDownloaders()
|
int |
getNumWaitingDownloads()
|
void |
handleQueryReply(QueryReply qr)
Adds all responses (and alternates) in qr to any downloaders, if appropriate. |
void |
initialize()
Initializes this manager. |
void |
measureBandwidth()
Calls measureBandwidth on each uploader. |
void |
postGuiInit()
Performs the slow, low-priority initialization tasks: reading in snapshots and scheduling snapshot checkpointing. |
boolean |
readSnapshot(java.io.File file)
Reads the downloaders serialized in DOWNLOAD_SNAPSHOT_FILE and adds them to this, queued. |
void |
remove(ManagedDownloader downloader,
boolean success)
Removes downloader entirely from the list of current downloads. |
boolean |
sendPush(RemoteFileDesc file)
Sends a push request for the given file. |
boolean |
sendQuery(ManagedDownloader requerier,
QueryRequest query)
Attempts to send the given requery to provide the given downloader with more sources to download. |
void |
waitForSlot(ManagedDownloader downloader)
Blocks until a download slot has been assigned to downloader. |
void |
yieldSlot(ManagedDownloader downloader)
Relinquishes downloader's slot. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static long TIME_BETWEEN_REQUERIES
com.limegroup.gnutella.downloader.ManagedDownloader#TIME_BETWEEN_REQUERIES
Constructor Detail |
public DownloadManager()
Method Detail |
public void initialize()
public void postGuiInit()
public IncompleteFileManager getIncompleteFileManager()
public int downloadsInProgress()
public int getNumIndividualDownloaders()
public int getNumActiveDownloads()
public int getNumWaitingDownloads()
public boolean readSnapshot(java.io.File file)
file
- the downloads.dat snapshot filepublic Downloader download(RemoteFileDesc[] files, java.util.List alts, boolean overwrite) throws FileExistsException, AlreadyDownloadingException, java.io.FileNotFoundException
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 ActivityCallback 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.
FileExistsException
AlreadyDownloadingException
java.io.FileNotFoundException
public Downloader download(URN urn, java.lang.String textQuery, java.lang.String filename, java.lang.String[] defaultURL) throws java.lang.IllegalArgumentException, AlreadyDownloadingException
urn
- the hash of the file (exact topic), or null if unknowntextQuery
- requery keywords (keyword topic), or null if unknownfilename
- the final file name, or null if unknown
AlreadyDownloadingException
- couldn't download because the
another downloader is getting the file
java.lang.IllegalArgumentException
- both urn and textQuery are nullpublic Downloader download(java.io.File incompleteFile) throws AlreadyDownloadingException, CantResumeException
AlreadyDownloadingException
- couldn't download because the
another downloader is getting the file
CantResumeException
- incompleteFile is not a valid
incomplete filepublic Downloader download(java.lang.String query, java.lang.String richQuery, byte[] guid, MediaType type) throws AlreadyDownloadingException
query
- The original query string.richQuery
- The original richQuery string.guid
- The guid associated with this query request.type
- The mediatype associated with this search.
AlreadyDownloadingException
public java.lang.String conflicts(RemoteFileDesc[] files, ManagedDownloader dloader)
public void handleQueryReply(QueryReply qr)
public void acceptDownload(java.net.Socket socket)
public void waitForSlot(ManagedDownloader downloader) throws java.lang.InterruptedException
java.lang.InterruptedException
public void yieldSlot(ManagedDownloader downloader)
public void remove(ManagedDownloader downloader, boolean success)
public boolean sendQuery(ManagedDownloader requerier, QueryRequest query)
query
- the requery to send, which should have a marked GUID.
Queries are subjected to global rate limiting iff they have marked
requery GUIDs.requerier
- the downloader requesting more sources. Needed to
ensure fair requery scheduling. This MUST be in the waiting list,
i.e., it MUST NOT have a download slot.
public boolean sendPush(RemoteFileDesc file)
file
- the RemoteFileDesc constructed from the query
hit, containing data about the host we're pushing to
public void measureBandwidth()
measureBandwidth
in interface BandwidthTracker
public float getMeasuredBandwidth()
getMeasuredBandwidth
in interface BandwidthTracker
public float getAverageBandwidth()
getAverageBandwidth
in interface BandwidthTracker
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |