LimeWire Consolidated API

com.limegroup.gnutella
Class DownloadManagerImpl

java.lang.Object
  extended by com.limegroup.gnutella.DownloadManagerImpl
All Implemented Interfaces:
BandwidthTracker, LWSIntegrationServicesDelegate, PushedSocketHandler, DownloadManager, SaveLocationManager, Service, EventListener<ManagedListStatusEvent>, ListenerSupport<DownloadManagerEvent>

public class DownloadManagerImpl
extends Object
implements DownloadManager, Service, EventListener<ManagedListStatusEvent>


Constructor Summary
DownloadManagerImpl(DownloadCallback innetworkCallback, com.google.inject.Provider<DownloadCallback> downloadCallback, com.google.inject.Provider<MessageRouter> messageRouter, ScheduledExecutorService backgroundExecutor, com.google.inject.Provider<TorrentManager> torrentManager, com.google.inject.Provider<PushDownloadManager> pushDownloadManager, CoreDownloaderFactory coreDownloaderFactory, DownloadSerializer downloaderSerializer, IncompleteFileManager incompleteFileManager, RemoteFileDescFactory remoteFileDescFactory, BTMetaInfoFactory btMetaInfoFactory, PushEndpointFactory pushEndpointFactory)
           
 
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 addListener(EventListener<DownloadManagerEvent> listener)
          Adds the listener.
 void addNewDownloader(CoreDownloader downloader)
          Adds a new downloader to this 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)
           
 Downloader getDownloaderForURNString(String urn)
           
 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()
           
 String getServiceName()
           
 void handleEvent(ManagedListStatusEvent evt)
          Listens for events from FileManager
 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.
 void initialize()
           
 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 loadSavedDownloads()
           
 void loadSavedDownloadsAndScheduleWriting()
          Performs the slow, low-priority initialization tasks: reading in snapshots and scheduling snapshot checkpointing.
 void measureBandwidth()
          Calls measureBandwidth on each uploader.
 CoreDownloader prepareMemento(DownloadMemento memento)
           
protected  void pumpDownloads()
          Pumps through each waiting download, either removing it because it was stopped, or adding it because there's an active slot and it requires attention.
 void register(PushedSocketHandlerRegistry registry)
           
 void remove(CoreDownloader downloader, boolean completed)
          Removes downloader entirely from the list of current downloads.
 boolean removeListener(EventListener<DownloadManagerEvent> listener)
          Returns true if the listener was removed.
 void scheduleSnapshots()
           
 void scheduleWaitingPump()
           
 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 stop()
           
 void visitDownloads(Visitor<CoreDownloader> visitor)
           
 void writeSnapshot()
          Writes a snapshot of all downloaders in this and all incomplete files to the file named DOWNLOAD_SNAPSHOT_FILE.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DownloadManagerImpl

@Inject
public DownloadManagerImpl(DownloadCallback innetworkCallback,
                                  com.google.inject.Provider<DownloadCallback> downloadCallback,
                                  com.google.inject.Provider<MessageRouter> messageRouter,
                                  ScheduledExecutorService backgroundExecutor,
                                  com.google.inject.Provider<TorrentManager> torrentManager,
                                  com.google.inject.Provider<PushDownloadManager> pushDownloadManager,
                                  CoreDownloaderFactory coreDownloaderFactory,
                                  DownloadSerializer downloaderSerializer,
                                  IncompleteFileManager incompleteFileManager,
                                  RemoteFileDescFactory remoteFileDescFactory,
                                  BTMetaInfoFactory btMetaInfoFactory,
                                  PushEndpointFactory pushEndpointFactory)
Method Detail

register

@Inject
public void register(PushedSocketHandlerRegistry registry)

start

public void start()
Description copied from interface: DownloadManager
Initializes this manager. This method must be called before any other methods are used.

Specified by:
start in interface DownloadManager
Specified by:
start in interface Service

getServiceName

public String getServiceName()
Specified by:
getServiceName in interface Service

initialize

public void initialize()
Specified by:
initialize in interface Service

stop

public void stop()
Specified by:
stop in interface Service

addNewDownloader

public void addNewDownloader(CoreDownloader downloader)
Adds a new downloader to this manager.

Specified by:
addNewDownloader in interface DownloadManager
Parameters:
downloader - the core downloader

loadSavedDownloadsAndScheduleWriting

public void loadSavedDownloadsAndScheduleWriting()
Description copied from interface: DownloadManager
Performs the slow, low-priority initialization tasks: reading in snapshots and scheduling snapshot checkpointing.

Specified by:
loadSavedDownloadsAndScheduleWriting in interface DownloadManager

loadSavedDownloads

public void loadSavedDownloads()

prepareMemento

public CoreDownloader prepareMemento(DownloadMemento memento)

scheduleSnapshots

public void scheduleSnapshots()

writeSnapshot

public void writeSnapshot()
Description copied from interface: DownloadManager
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.

Specified by:
writeSnapshot in interface DownloadManager

isSavedDownloadsLoaded

public boolean isSavedDownloadsLoaded()
Description copied from interface: DownloadManager
True if saved downloads have been loaded from disk.

Specified by:
isSavedDownloadsLoaded in interface DownloadManager

hasInNetworkDownload

public boolean hasInNetworkDownload()
Description copied from interface: DownloadManager
Determines if an 'In Network' download exists in either active or waiting.

Specified by:
hasInNetworkDownload in interface DownloadManager

killDownloadersNotListed

public void killDownloadersNotListed(Collection<? extends DownloadInformation> updates)
Description copied from interface: DownloadManager
Kills all in-network downloaders that are not present in the list of DownloadInformations

Specified by:
killDownloadersNotListed in interface DownloadManager
Parameters:
updates - a current set of DownloadInformation that we are downloading in-network.

acceptPushedSocket

public 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
Specified by:
acceptPushedSocket in interface DownloadManager
Returns:
true if the handler accepted the socket

scheduleWaitingPump

public void scheduleWaitingPump()

pumpDownloads

protected void pumpDownloads()
Pumps through each waiting download, either removing it because it was stopped, or adding it because there's an active slot and it requires attention.


isIncomplete

public boolean isIncomplete(URN urn)
Description copied from interface: DownloadManager
Determines if the given URN has an incomplete file.

Specified by:
isIncomplete in interface DownloadManager

isActivelyDownloading

public boolean isActivelyDownloading(URN urn)
Description copied from interface: DownloadManager
Returns whether or not we are actively downloading this file.

Specified by:
isActivelyDownloading in interface DownloadManager

getIncompleteFileManager

public IncompleteFileManager getIncompleteFileManager()
Description copied from interface: DownloadManager
Returns the IncompleteFileManager used by this DownloadManager and all ManagedDownloaders.

Specified by:
getIncompleteFileManager in interface DownloadManager

downloadsInProgress

public int downloadsInProgress()
Specified by:
downloadsInProgress in interface DownloadManager

getNumIndividualDownloaders

public int getNumIndividualDownloaders()
Specified by:
getNumIndividualDownloaders in interface DownloadManager

getNumActiveDownloads

public int getNumActiveDownloads()
Description copied from interface: DownloadManager
Inner network traffic and downloads from the LWS don't count towards overall download activity.

Specified by:
getNumActiveDownloads in interface DownloadManager

getNumWaitingDownloads

public int getNumWaitingDownloads()
Specified by:
getNumWaitingDownloads in interface DownloadManager

getDownloaderForURN

public Downloader getDownloaderForURN(URN sha1)
Specified by:
getDownloaderForURN in interface DownloadManager

getDownloaderForURNString

public Downloader getDownloaderForURNString(String urn)

getDownloaderForIncompleteFile

public Downloader getDownloaderForIncompleteFile(File file)
Description copied from interface: DownloadManager
Returns the active or waiting downloader that uses or will use file as incomplete file.

Specified by:
getDownloaderForIncompleteFile in interface DownloadManager
Parameters:
file - the incomplete file candidate
Returns:
null if no downloader for the file is found

isGuidForQueryDownloading

public boolean isGuidForQueryDownloading(GUID guid)
Specified by:
isGuidForQueryDownloading in interface DownloadManager

download

public Downloader download(RemoteFileDesc[] files,
                           List<? extends RemoteFileDesc> alts,
                           GUID queryGUID,
                           boolean overwrite,
                           File saveDir,
                           String fileName)
                    throws SaveLocationException
Description copied from interface: DownloadManager
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.

Specified by:
download in interface DownloadManager
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

public Downloader download(MagnetOptions magnet,
                           boolean overwrite,
                           File saveDir,
                           String fileName)
                    throws IllegalArgumentException,
                           SaveLocationException
Description copied from interface: DownloadManager
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.

Specified by:
download in interface DownloadManager
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
Throws:
IllegalArgumentException - if the magnet is not downloadable
SaveLocationException - if the file can't save because of an existing file in the location

downloadFromStore

public Downloader downloadFromStore(RemoteFileDesc rfd,
                                    boolean overwrite,
                                    File saveDir,
                                    String fileName)
                             throws IllegalArgumentException,
                                    SaveLocationException
Description copied from interface: DownloadManager
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.

Specified by:
downloadFromStore in interface DownloadManager
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

public Downloader download(File incompleteFile)
                    throws CantResumeException,
                           SaveLocationException
Description copied from interface: DownloadManager
Starts a resume download for the given incomplete file.

Specified by:
download in interface DownloadManager
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

public Downloader download(DownloadInformation info,
                           long now)
                    throws SaveLocationException
Description copied from interface: DownloadManager
Downloads an InNetwork update, using the info from the DownloadInformation.

Specified by:
download in interface DownloadManager
Throws:
SaveLocationException

downloadTorrent

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

Specified by:
downloadTorrent in interface DownloadManager
Throws:
SaveLocationException

downloadTorrent

public Downloader downloadTorrent(File torrentFile,
                                  boolean overwrite)
                           throws SaveLocationException
Description copied from interface: DownloadManager
Opens the torrent for the specified file, and begins the torrent download.

Specified by:
downloadTorrent in interface DownloadManager
Throws:
SaveLocationException

downloadTorrent

public Downloader downloadTorrent(BTMetaInfo info,
                                  boolean overwrite)
                           throws SaveLocationException
Description copied from interface: DownloadManager
Downloads the given torrent specified by the meta info object.

Specified by:
downloadTorrent in interface DownloadManager
Throws:
SaveLocationException

downloadFromMozilla

public Downloader downloadFromMozilla(MozillaDownload listener)
Description copied from interface: DownloadManager
Creates a Downloader wrapping the MozillaDownloadListener. Adds capability to track status of mozilla download.

Specified by:
downloadFromMozilla in interface DownloadManager

conflicts

public boolean conflicts(URN urn,
                         long fileSize,
                         File... fileName)
Description copied from interface: DownloadManager
Returns true if there already is a download with the same urn.

Specified by:
conflicts in interface DownloadManager
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

public boolean isSaveLocationTaken(File candidateFile)
Description copied from interface: DownloadManager
Returns true if there already is a download that is or will be saving to this file location.

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

handleQueryReply

public void handleQueryReply(QueryReply qr,
                             Address address)
Description copied from interface: DownloadManager
Adds all responses (and alternates) in qr to any downloaders, if appropriate.

Specified by:
handleQueryReply in interface DownloadManager
address - can be null, otherwise overrides the address information in qr

remove

public void remove(CoreDownloader downloader,
                   boolean completed)
Description copied from interface: DownloadManager
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.

Specified by:
remove in interface DownloadManager

bumpPriority

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

Specified by:
bumpPriority in interface DownloadManager

sendQuery

public void sendQuery(QueryRequest query)
Description copied from interface: DownloadManager
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.

Specified by:
sendQuery in interface DownloadManager
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

public void measureBandwidth()
Description copied from interface: DownloadManager
Calls measureBandwidth on each uploader.

Specified by:
measureBandwidth in interface BandwidthTracker
Specified by:
measureBandwidth in interface DownloadManager

getMeasuredBandwidth

public float getMeasuredBandwidth()
Description copied from interface: DownloadManager
Returns the total upload throughput, i.e., the sum over all uploads.

Specified by:
getMeasuredBandwidth in interface BandwidthTracker
Specified by:
getMeasuredBandwidth in interface DownloadManager

getAverageBandwidth

public float getAverageBandwidth()
Description copied from interface: DownloadManager
returns the summed average of the downloads

Specified by:
getAverageBandwidth in interface BandwidthTracker
Specified by:
getAverageBandwidth in interface DownloadManager

getLastMeasuredBandwidth

public float getLastMeasuredBandwidth()
Description copied from interface: DownloadManager
Returns the measured bandwidth as calculated from the last getMeasuredBandwidth() call.

Specified by:
getLastMeasuredBandwidth in interface DownloadManager

getAllDownloaders

public final Iterable<CoreDownloader> getAllDownloaders()
Specified by:
getAllDownloaders in interface DownloadManager

handleEvent

public void handleEvent(ManagedListStatusEvent evt)
Listens for events from FileManager

Specified by:
handleEvent in interface EventListener<ManagedListStatusEvent>

visitDownloads

public void visitDownloads(Visitor<CoreDownloader> visitor)
Specified by:
visitDownloads in interface LWSIntegrationServicesDelegate

addListener

public void addListener(EventListener<DownloadManagerEvent> listener)
Description copied from interface: ListenerSupport
Adds the listener.

Specified by:
addListener in interface ListenerSupport<DownloadManagerEvent>

removeListener

public boolean removeListener(EventListener<DownloadManagerEvent> listener)
Description copied from interface: ListenerSupport
Returns true if the listener was removed.

Specified by:
removeListener in interface ListenerSupport<DownloadManagerEvent>

contains

public boolean contains(Downloader downloader)
Description copied from interface: DownloadManager
Returns true if the given downloader is in either the waiting or active lists.

Specified by:
contains in interface DownloadManager

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.