com.limegroup.gnutella.downloader
Class ResumeDownloader

java.lang.Object
  extended bycom.limegroup.gnutella.downloader.ManagedDownloader
      extended bycom.limegroup.gnutella.downloader.ResumeDownloader
All Implemented Interfaces:
BandwidthTracker, Downloader, java.io.Serializable

public class ResumeDownloader
extends ManagedDownloader
implements java.io.Serializable

A ManagedDownloader that tries to resume to a specific incomplete file. The ResumeDownloader initially has no locations to download from. Instead it immediately requeries--by hash if possible--and only accepts results that would result in resumes from the specified incomplete file. Do not be confused by the name; ManagedDownloader CAN resume from incomplete files, but it is less strict about its choice of download.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.limegroup.gnutella.downloader.ManagedDownloader
UNKNOWN_FILENAME
 
Fields inherited from interface com.limegroup.gnutella.Downloader
ABORTED, COMPLETE, CONNECTING, CORRUPT_FILE, COULDNT_MOVE_TO_LIBRARY, DOWNLOADING, GAVE_UP, HASHING, QUEUED, REMOTE_QUEUED, SAVING, WAITING_FOR_CONNECTIONS, WAITING_FOR_RESULTS, WAITING_FOR_RETRY, WAITING_FOR_USER
 
Constructor Summary
ResumeDownloader(IncompleteFileManager incompleteFileManager, java.io.File incompleteFile, java.lang.String name, int size)
          Creates a RequeryDownloader to finish downloading incompleteFile.
 
Method Summary
protected  boolean allowAddition(RemoteFileDesc other)
          Overrides ManagedDownloader to allow any RemoteFileDesc that would resume from _incompleteFile.
 boolean conflicts(java.io.File incompleteFile)
          Overrides ManagedDownloader to reserve _incompleteFile for this download.
 int getContentLength()
          Overrides ManagedDownloader to display a reasonable file size even when no locations have been found.
 java.lang.String getFileName()
          Overrides ManagedDownloader to display a reasonable file name even when no locations have been found.
 void initialize(DownloadManager manager, FileManager fileManager, ActivityCallback callback, boolean deserialized)
          Overrides ManagedDownloader to ensure that progress is initially non-zero and file previewing works.
protected  QueryRequest newRequery(int numRequeries)
          Overrides ManagedDownloader to use the filename and hash (if present) of the incomplete file.
protected  boolean pauseForRequery(int numRequeries, boolean deserializedFromDisk)
          This dictates whether this downloader should wait for user input before spawning a Requery.
protected  boolean shouldInitAltLocs(boolean deserializedFromDisk)
          Subclasses should override this method when necessary.
 
Methods inherited from class com.limegroup.gnutella.downloader.ManagedDownloader
acceptDownload, addDownload, addDownloadForced, conflicts, discardCorruptDownload, finish, getAddress, getAmountRead, getAverageBandwidth, getBrowseEnabledHost, getBusyHostCount, getChatEnabledHost, getDownloadFragment, getFailedState, getHosts, getMeasuredBandwidth, getNumberOfAlternateLocations, getNumDownloaders, getPossibleHostCount, getQueryCount, getQueuedHostCount, getQueuePosition, getRemainingStateTime, getRetriesWaiting, getState, getVendor, hasBrowseEnabledHost, hasChatEnabledHost, hasRFD, initializeIncompleteFile, measureBandwidth, resume, stop, tryAllDownloads
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResumeDownloader

public ResumeDownloader(IncompleteFileManager incompleteFileManager,
                        java.io.File incompleteFile,
                        java.lang.String name,
                        int size)
Creates a RequeryDownloader to finish downloading incompleteFile. This constructor has preconditions on several parameters; putting the burden on the caller makes the method easier to implement, since the superclass constructor immediately starts a download thread.

Parameters:
incompleteFile - the incomplete file to resume to, which MUST be the result of IncompleteFileManager.getFile.
name - the name of the completed file, which MUST be the result of IncompleteFileManager.getCompletedName(incompleteFile)
size - the size of the completed file, which MUST be the result of IncompleteFileManager.getCompletedSize(incompleteFile)
Method Detail

initialize

public void initialize(DownloadManager manager,
                       FileManager fileManager,
                       ActivityCallback callback,
                       boolean deserialized)
Overrides ManagedDownloader to ensure that progress is initially non-zero and file previewing works.

Overrides:
initialize in class ManagedDownloader
Parameters:
deserialized - True if this downloader is being initialized after being read from disk, false otherwise.

conflicts

public boolean conflicts(java.io.File incompleteFile)
Overrides ManagedDownloader to reserve _incompleteFile for this download. That is, any download that would use the same incomplete file is rejected, even if this is not currently downloading.

Overrides:
conflicts in class ManagedDownloader

allowAddition

protected boolean allowAddition(RemoteFileDesc other)
Overrides ManagedDownloader to allow any RemoteFileDesc that would resume from _incompleteFile.

Overrides:
allowAddition in class ManagedDownloader

getContentLength

public int getContentLength()
Overrides ManagedDownloader to display a reasonable file size even when no locations have been found.

Specified by:
getContentLength in interface Downloader
Overrides:
getContentLength in class ManagedDownloader

getFileName

public java.lang.String getFileName()
Overrides ManagedDownloader to display a reasonable file name even when no locations have been found.

Specified by:
getFileName in interface Downloader
Overrides:
getFileName in class ManagedDownloader

pauseForRequery

protected boolean pauseForRequery(int numRequeries,
                                  boolean deserializedFromDisk)
                           throws java.lang.InterruptedException
Description copied from class: ManagedDownloader
This dictates whether this downloader should wait for user input before spawning a Requery. Subclasses should override with desired behavior as necessary.

Overrides:
pauseForRequery in class ManagedDownloader
Parameters:
numRequeries - The number of requeries sent so far.
deserializedFromDisk - If the downloader was deserialized from a snapshot. May be useful for subclasses.
Returns:
true if we the pause was broken because of new results. false if the user woke us up.
Throws:
java.lang.InterruptedException

shouldInitAltLocs

protected boolean shouldInitAltLocs(boolean deserializedFromDisk)
Description copied from class: ManagedDownloader
Subclasses should override this method when necessary. If you return false, then AltLocs are not initialized from the incomplete file upon invocation of tryAllDownloads. The true case can be used when the partial file is being shared through PFS and we've learned about AltLocs we want to use.

Overrides:
shouldInitAltLocs in class ManagedDownloader

newRequery

protected QueryRequest newRequery(int numRequeries)
Overrides ManagedDownloader to use the filename and hash (if present) of the incomplete file.

Overrides:
newRequery in class ManagedDownloader
Parameters:
numRequeries - the number of requeries that have already happened
Returns:
a new QueryRequest for making the requery