com.limegroup.gnutella
Interface Downloader

All Superinterfaces:
BandwidthTracker
All Known Implementing Classes:
ManagedDownloader

public interface Downloader
extends BandwidthTracker

The downloader interface. The UI maintains a list of Downloader's and uses its methods to stop and resume downloads. Note that there is no start method; it is assumed that the downloader will start as soon as it is instantiated.


Field Summary
static int ABORTED
           
static int COMPLETE
           
static int CONNECTING
           
static int CORRUPT_FILE
           
static int COULDNT_MOVE_TO_LIBRARY
           
static int DOWNLOADING
           
static int GAVE_UP
          When a downloader is in the GAVE_UP state, it can still try downloading if matching results pour in.
static int HASHING
           
static int QUEUED
           
static int REMOTE_QUEUED
           
static int SAVING
           
static int WAITING_FOR_CONNECTIONS
           
static int WAITING_FOR_RESULTS
           
static int WAITING_FOR_RETRY
           
static int WAITING_FOR_USER
           
 
Method Summary
 void discardCorruptDownload(boolean delete)
          either treats a corrupt file as normal file and saves it, or discards the corruptFile, depending on the value of delete.
 java.lang.String getAddress()
          Returns the last address that this tried to connect to, or null if it hasn't tried any.
 int getAmountRead()
          Returns the amount read by this so far, in bytes.
 RemoteFileDesc getBrowseEnabledHost()
          Returns a browse-enabled Endpoint instance for this Downloader.
 int getBusyHostCount()
           
 Endpoint getChatEnabledHost()
          Returns a chat-enabled Endpoint instance for this Downloader.
 int getContentLength()
          Returns the size of this file in bytes, i.e., the total amount to download.
 java.io.File getDownloadFragment()
          If this download is not yet complete, returns a copy of the first contiguous fragment of the incomplete file.
 java.lang.String getFileName()
          Returns the name of the current or last file this is downloading, or null in the rare case that this has no more files to download.
 java.util.Iterator getHosts()
          Returns the locations from which this is currently downloading, as an iterator of Endpoint.
 int getNumberOfAlternateLocations()
          Return the number of validated alternate locations for this download
 int getPossibleHostCount()
           
 int getQueuedHostCount()
           
 java.lang.String getQueuePosition()
          Returns the position of the download on the uploader, relavent only if the downloader is queueud.
 int getRemainingStateTime()
          Returns an upper bound on the amount of time this will stay in the current state, in seconds.
 int getRetriesWaiting()
          Returns the number of retries this is waiting for.
 int getState()
          Returns the state of this: one of QUEUED, CONNECTING, DOWNLOADING, WAITING_FOR_RETRY, COMPLETE, ABORTED, GAVE_UP, COULDNT_MOVE_TO_LIBRARY, WAITING_FOR_RESULTS, or CORRUPT_FILE
 java.lang.String getVendor()
          Returns the vendor of the last downloading host.
 boolean hasBrowseEnabledHost()
          Returns whether or not there is a browse-enabled host available for this Downloader.
 boolean hasChatEnabledHost()
          Returns whether or not there is a chat-enabled host available for this Downloader.
 boolean resume()
          Resumes this.
 void stop()
          Stops this.
 
Methods inherited from interface com.limegroup.gnutella.BandwidthTracker
getAverageBandwidth, getMeasuredBandwidth, measureBandwidth
 

Field Detail

QUEUED

public static final int QUEUED
See Also:
Constant Field Values

CONNECTING

public static final int CONNECTING
See Also:
Constant Field Values

DOWNLOADING

public static final int DOWNLOADING
See Also:
Constant Field Values

WAITING_FOR_RETRY

public static final int WAITING_FOR_RETRY
See Also:
Constant Field Values

COMPLETE

public static final int COMPLETE
See Also:
Constant Field Values

ABORTED

public static final int ABORTED
See Also:
Constant Field Values

GAVE_UP

public static final int GAVE_UP
When a downloader is in the GAVE_UP state, it can still try downloading if matching results pour in. So you should 'stop' downloaders that are in the GAVE_UP state.

See Also:
Constant Field Values

COULDNT_MOVE_TO_LIBRARY

public static final int COULDNT_MOVE_TO_LIBRARY
See Also:
Constant Field Values

WAITING_FOR_RESULTS

public static final int WAITING_FOR_RESULTS
See Also:
Constant Field Values

CORRUPT_FILE

public static final int CORRUPT_FILE
See Also:
Constant Field Values

REMOTE_QUEUED

public static final int REMOTE_QUEUED
See Also:
Constant Field Values

HASHING

public static final int HASHING
See Also:
Constant Field Values

SAVING

public static final int SAVING
See Also:
Constant Field Values

WAITING_FOR_USER

public static final int WAITING_FOR_USER
See Also:
Constant Field Values

WAITING_FOR_CONNECTIONS

public static final int WAITING_FOR_CONNECTIONS
See Also:
Constant Field Values
Method Detail

stop

public void stop()
Stops this. If the download is already stopped, does nothing.


resume

public boolean resume()
               throws AlreadyDownloadingException
Resumes this. If the download is GAVE_UP, tries all locations again and returns true. If WAITING_FOR_RETRY, forces the retry immediately and returns true. If some other downloader is currently downloading the file, throws AlreadyDowloadingException. If WAITING_FOR_USER, then launches another query. Otherwise does nothing and returns false.

Throws:
AlreadyDownloadingException

getDownloadFragment

public java.io.File getDownloadFragment()
If this download is not yet complete, returns a copy of the first contiguous fragment of the incomplete file. (The copying helps prevent file locking problems.) Returns null if the download hasn't started or the copy failed. If the download is complete, returns the saved file.

Returns:
the copied file fragment, saved file, or null

getState

public int getState()
Returns the state of this: one of QUEUED, CONNECTING, DOWNLOADING, WAITING_FOR_RETRY, COMPLETE, ABORTED, GAVE_UP, COULDNT_MOVE_TO_LIBRARY, WAITING_FOR_RESULTS, or CORRUPT_FILE


getRemainingStateTime

public int getRemainingStateTime()
Returns an upper bound on the amount of time this will stay in the current state, in seconds. Returns Integer.MAX_VALUE if unknown.


getFileName

public java.lang.String getFileName()
Returns the name of the current or last file this is downloading, or null in the rare case that this has no more files to download. (This might happen if this has been stopped.)


getContentLength

public int getContentLength()
Returns the size of this file in bytes, i.e., the total amount to download.


getAmountRead

public int getAmountRead()
Returns the amount read by this so far, in bytes.


getRetriesWaiting

public int getRetriesWaiting()
Returns the number of retries this is waiting for. Result meaningful on in WAIT_FOR_RETRY state.


getAddress

public java.lang.String getAddress()
Returns the last address that this tried to connect to, or null if it hasn't tried any. Useful primarily for CONNECTING.


getHosts

public java.util.Iterator getHosts()
Returns the locations from which this is currently downloading, as an iterator of Endpoint. If this is swarming, may return multiple addresses. Result meaningful only in the DOWNLOADING state.


getVendor

public java.lang.String getVendor()
Returns the vendor of the last downloading host.


getChatEnabledHost

public Endpoint getChatEnabledHost()
Returns a chat-enabled Endpoint instance for this Downloader.


hasChatEnabledHost

public boolean hasChatEnabledHost()
Returns whether or not there is a chat-enabled host available for this Downloader.

Returns:
true if there is a chat-enabled host for this Downloader, false otherwise

discardCorruptDownload

public void discardCorruptDownload(boolean delete)
either treats a corrupt file as normal file and saves it, or discards the corruptFile, depending on the value of delete.


getBrowseEnabledHost

public RemoteFileDesc getBrowseEnabledHost()
Returns a browse-enabled Endpoint instance for this Downloader.


hasBrowseEnabledHost

public boolean hasBrowseEnabledHost()
Returns whether or not there is a browse-enabled host available for this Downloader.

Returns:
true if there is a browse-enabled host for this Downloader, false otherwise

getQueuePosition

public java.lang.String getQueuePosition()
Returns the position of the download on the uploader, relavent only if the downloader is queueud.


getNumberOfAlternateLocations

public int getNumberOfAlternateLocations()
Return the number of validated alternate locations for this download


getPossibleHostCount

public int getPossibleHostCount()
Returns:
the number of possible hosts for this download

getBusyHostCount

public int getBusyHostCount()
Returns:
the number of hosts we tried which were busy. We will try these later

getQueuedHostCount

public int getQueuedHostCount()
Returns:
the number of hosts we are remotely queued on.