com.limegroup.gnutella.downloader
Class RequeryDownloader

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

public class RequeryDownloader
extends ManagedDownloader
implements java.io.Serializable

A wishlist ManagedDownloader. This is initially with only a list of search keywords (e.g., from the user)--with no RemoteFileDesc's. It will requery the network with the given keywords. When it gets a result that matches the query, it will start downloading from that location. Subsequently this will behave like a standard ManagedDownloader, only accepting RemoteFileDesc's matching the current set of RemoteFileDesc's.

See Also:
Serialized Form

Field Summary
protected  AutoDownloadDetails _add
          Contains the specifics of the search that spawned me.
 
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
RequeryDownloader(IncompleteFileManager incompleteFileManager, AutoDownloadDetails add)
          Creates a new RequeryDownloader - a RequeryDownloader has no files initially associated with it, but it may have them later (via calls to addDownload().
 
Method Summary
protected  boolean allowAddition(RemoteFileDesc other)
          Overrides ManagedDownloader to allow any RemoteFileDesc that matches this' keywords.
 boolean conflicts(AutoDownloadDetails add)
          Returns true if the parameters of the add are sufficiently similar such that spawning a new RequeryDownloader would be redundant.
 int getContentLength()
          Need to override this until ManagedDownloader has a allFiles of non-zero length.
protected  long[] getFailedState(boolean deserialized, long timeSpentWaiting)
          This method is called when 1) all downloads sources failed 2) there are no busy hosts 3) there is no room for a requery Subclasses should override this method if they want to enforce special behavior before going to the GAVE_UP state.
 java.lang.String getFileName()
          Need to override this until ManagedDownloader has a allFiles of non-zero length.
protected  int getQueryCount(boolean deserializedFromDisk)
          We need to offer this to subclasses to override because they might have specific behavior when deserialized from disk.
protected  QueryRequest newRequery(int numRequeries)
          Overrides ManagedDownloader to use the original search keywords.
 
Methods inherited from class com.limegroup.gnutella.downloader.ManagedDownloader
acceptDownload, addDownload, addDownloadForced, conflicts, conflicts, discardCorruptDownload, finish, getAddress, getAmountRead, getAverageBandwidth, getBrowseEnabledHost, getBusyHostCount, getChatEnabledHost, getDownloadFragment, getHosts, getMeasuredBandwidth, getNumberOfAlternateLocations, getNumDownloaders, getPossibleHostCount, getQueuedHostCount, getQueuePosition, getRemainingStateTime, getRetriesWaiting, getState, getVendor, hasBrowseEnabledHost, hasChatEnabledHost, hasRFD, initialize, initializeIncompleteFile, measureBandwidth, pauseForRequery, resume, shouldInitAltLocs, stop, tryAllDownloads
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_add

protected AutoDownloadDetails _add
Contains the specifics of the search that spawned me. Important for requerying....

Constructor Detail

RequeryDownloader

public RequeryDownloader(IncompleteFileManager incompleteFileManager,
                         AutoDownloadDetails add)
Creates a new RequeryDownloader - a RequeryDownloader has no files initially associated with it, but it may have them later (via calls to addDownload(). Non-blocking.

Parameters:
incompleteFileManager - the repository of incomplete files for resuming
add - the keywords to requery with
Method Detail

conflicts

public boolean conflicts(AutoDownloadDetails add)
Returns true if the parameters of the add are sufficiently similar such that spawning a new RequeryDownloader would be redundant.


getFailedState

protected long[] getFailedState(boolean deserialized,
                                long timeSpentWaiting)
Description copied from class: ManagedDownloader
This method is called when 1) all downloads sources failed 2) there are no busy hosts 3) there is no room for a requery Subclasses should override this method if they want to enforce special behavior before going to the GAVE_UP state. NOTE: Only the following states are can be preemptively woken up due to new results - WAITING_FOR_RETRY, WAITING_FOR_RESULTS, and GAVE_UP.

Overrides:
getFailedState in class ManagedDownloader
Parameters:
deserialized - true if this downloader was initialized from disk, false if it is brand new.
timeSpentWaiting - the millisecond time that the downloader has spent in the failed state.
Returns:
two longs - long[0] is the state the downloader should go in. long[1] is the time the downloader should spend in state long[0]. if long[1] < 1, this return value is ignored.

getQueryCount

protected int getQueryCount(boolean deserializedFromDisk)
Description copied from class: ManagedDownloader
We need to offer this to subclasses to override because they might have specific behavior when deserialized from disk. for example, RequeryDowloader should return a count of 0 upon deserialization, but 1 if started from scratch.

Overrides:
getQueryCount in class ManagedDownloader

newRequery

protected QueryRequest newRequery(int numRequeries)
                           throws CantResumeException
Overrides ManagedDownloader to use the original search keywords.

Overrides:
newRequery in class ManagedDownloader
Parameters:
numRequeries - the number of requeries that have already happened
Returns:
a new QueryRequest for making the requery
Throws:
CantResumeException - if this doesn't know what to search for

allowAddition

protected boolean allowAddition(RemoteFileDesc other)
Overrides ManagedDownloader to allow any RemoteFileDesc that matches this' keywords. If a match has already been found and a download has been started, only allows those RemoteFileDesc's that actually match the download.

Overrides:
allowAddition in class ManagedDownloader

getFileName

public java.lang.String getFileName()
Need to override this until ManagedDownloader has a allFiles of non-zero length.

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

getContentLength

public int getContentLength()
Need to override this until ManagedDownloader has a allFiles of non-zero length.

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