org.gudy.azureus2.pluginsimpl.local.download
Class DownloadManagerImpl

java.lang.Object
  extended by org.gudy.azureus2.pluginsimpl.local.download.DownloadManagerImpl
All Implemented Interfaces:
DownloadManagerInitialisationAdapter, DownloadManager

public class DownloadManagerImpl
extends java.lang.Object
implements DownloadManager, DownloadManagerInitialisationAdapter


Field Summary
protected static AEMonitor class_mon
           
protected static DownloadManagerImpl singleton
           
 
Fields inherited from interface org.gudy.azureus2.core3.download.DownloadManagerInitialisationAdapter
ACT_ASSIGNS_TAGS, ACT_NONE, ACT_PROCESSES_TAGS
 
Constructor Summary
protected DownloadManagerImpl(AzureusCore _azureus_core)
           
 
Method Summary
 void addDownload(java.io.File fileName)
          Add a torrent from a file.
 Download addDownload(Torrent torrent)
          Add a torrent from a "Torrent" object.
 Download addDownload(Torrent torrent, java.io.File torrent_file, java.io.File data_location)
          Add a torrent from a "Torrent" object and point it at the data location.
 Download addDownload(Torrent torrent, java.io.File torrent_file, java.io.File data_location, int initial_state)
           
 void addDownload(java.net.URL url)
          add a torrent from a URL.
 void addDownload(java.net.URL url, boolean auto_download)
          Add a torrent from a URL with explicit auto-download option
 void addDownload(java.net.URL url, java.util.Map request_properties)
          add a torrent from a URL and use the supplied request properties
 void addDownload(java.net.URL url, java.net.URL referrer)
          add a torrent from a URL.
 void addDownload(java.net.URL url, java.net.URL referrer, boolean auto_download, java.util.Map request_properties)
           
protected  void addDownloadManager(DownloadManager dm)
           
 Download addDownloadStopped(Torrent torrent, java.io.File torrent_location, java.io.File data_location)
          Explicit way of adding a download in a stopped state
 void addDownloadStubListener(DownloadStubListener l, boolean inform_of_current)
           
 void addDownloadWillBeAddedListener(DownloadWillBeAddedListener listener)
           
 void addExternalDownload(Download download)
           
 void addListener(DownloadManagerListener l)
          Add a listener that will be informed when a download is added to and removed from Azureus.
 void addListener(DownloadManagerListener l, boolean notify_of_current_downloads)
          Add a listener that will be informed when a download is added to and removed from Azureus.
 Download addNonPersistentDownload(Torrent torrent, java.io.File torrent_file, java.io.File data_location)
          Add a non-persistent download.
 Download addNonPersistentDownloadStopped(Torrent torrent, java.io.File torrent_file, java.io.File data_location)
           
 boolean canPauseDownloads()
           
 boolean canResumeDownloads()
           
 boolean canStubbify(DownloadImpl download)
           
 void clearNonPersistentDownloadState(byte[] hash)
          Although non-persistent downloads themselves aren't rememebered across restarts, some internal stats are (for continuity, like total up/down, file allocation state) - this method allows this to be removed
protected  Download destubbify(DownloadStubImpl stub)
           
 int getActions()
          Unfortuately order can be important when firing off initialisation adapters, in particular if one listener assigns tags to a download it needs to do this before any other listeners that might process a download's tags
 DefaultSaveLocationManager getDefaultSaveLocationManager()
          Returns the default SaveLocationManager object that controls where downloads should be placed.
 Download getDownload(byte[] hash)
          Gets a download given its hash
 Download getDownload(DiskManager dm)
           
protected  DownloadImpl getDownload(DownloadManager dm)
           
 Download getDownload(Torrent _torrent)
          Gets the download for a particular torrent, returns null if not found
protected  Download getDownload(TOTorrent torrent)
           
 Download[] getDownloads()
          Gets all the downloads.
 Download[] getDownloads(boolean bSorted)
          Gets all the downloads.
static Download getDownloadStatic(DiskManager dm)
           
static DownloadImpl getDownloadStatic(DownloadManager dm)
          Retrieve the plugin Downlaod object related to the DownloadManager
static DownloadImpl[] getDownloadStatic(DownloadManager[] dm)
           
static Download getDownloadStatic(TOTorrent torrent)
           
 int getDownloadStubCount()
           
 DownloadStub[] getDownloadStubs()
           
 DownloadEventNotifier getGlobalDownloadEventNotifier()
          Return a DownloadEventNotifier object which can be used as an easy way to register listeners against all downloads handled by Azureus.
protected  int getInitialState()
           
 SaveLocationManager getSaveLocationManager()
          Returns the current SaveLocationManager object which decides where downloads should be placed.
static DownloadManagerImpl getSingleton(AzureusCore azureus_core)
           
 DownloadManagerStats getStats()
          Get the download manager statistics
static TOTorrent getStubTorrent(byte[] hash)
           
protected  TOTorrent getTorrent(DownloadStubImpl stub)
           
 void initialised(DownloadManager manager, boolean for_seeding)
           
 boolean isSeedingOnly()
          indicates whether or not all active downloads are in a seeding (or effective) seeding state
 DownloadStub lookupDownloadStub(byte[] hash)
           
 void pauseDownloads()
          pause all running downloads
protected  void remove(DownloadStubImpl stub)
           
 void removeDownloadStubListener(DownloadStubListener l)
           
 void removeDownloadWillBeAddedListener(DownloadWillBeAddedListener listener)
           
 void removeExternalDownload(Download download)
           
 void removeListener(DownloadManagerListener l)
          Removes a previously added listener.
 void removeListener(DownloadManagerListener l, boolean notify_of_current_downloads)
          Removes a previously added listener.
 void resumeDownloads()
          resume previously paused downloads
 void setSaveLocationManager(SaveLocationManager manager)
          Registers an object to be in control of determining the default save location for downloads.
 void startAllDownloads()
          starts all non-running downloads
 void stopAllDownloads()
          stops all running downloads
protected  DownloadStub stubbify(DownloadImpl download)
           
protected  void updated(DownloadStubImpl stub)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

protected static DownloadManagerImpl singleton

class_mon

protected static AEMonitor class_mon
Constructor Detail

DownloadManagerImpl

protected DownloadManagerImpl(AzureusCore _azureus_core)
Method Detail

getSingleton

public static DownloadManagerImpl getSingleton(AzureusCore azureus_core)

addDownload

public void addDownload(java.io.File fileName)
Description copied from interface: DownloadManager
Add a torrent from a file. This may prompt the user for a download location etc. if required. This is an async operation, so no Download is returned. If you want to force a download to be added without prompting the user, you should create a Torrent object first, and then use an alternative addDownload method.

Specified by:
addDownload in interface DownloadManager
See Also:
DownloadManager.addDownload(Torrent), DownloadManager.addDownload(Torrent, File, File), TorrentManager.createFromBEncodedFile

addDownload

public void addDownload(java.net.URL url)
Description copied from interface: DownloadManager
add a torrent from a URL. This will prompt the user for download location etc. if required This is an async operation so no Download returned

Specified by:
addDownload in interface DownloadManager

addDownload

public void addDownload(java.net.URL url,
                        boolean auto_download)
                 throws DownloadException
Description copied from interface: DownloadManager
Add a torrent from a URL with explicit auto-download option

Specified by:
addDownload in interface DownloadManager
Throws:
DownloadException

addDownload

public void addDownload(java.net.URL url,
                        java.net.URL referrer)
Description copied from interface: DownloadManager
add a torrent from a URL. This will prompt the user for download location etc. if required This is an async operation so no Download returned

Specified by:
addDownload in interface DownloadManager

addDownload

public void addDownload(java.net.URL url,
                        java.util.Map request_properties)
Description copied from interface: DownloadManager
add a torrent from a URL and use the supplied request properties

Specified by:
addDownload in interface DownloadManager

addDownload

public void addDownload(java.net.URL url,
                        java.net.URL referrer,
                        boolean auto_download,
                        java.util.Map request_properties)

addDownloadManager

protected void addDownloadManager(DownloadManager dm)

addDownload

public Download addDownload(Torrent torrent)
                     throws DownloadException
Description copied from interface: DownloadManager
Add a torrent from a "Torrent" object. The default torrent file and data locations will be used if defined - a DownloadException will be thrown if they're not. You can explicitly set these values by using the addDownload(Torrent, File, File) method.

Specified by:
addDownload in interface DownloadManager
Returns:
Throws:
DownloadException
See Also:
DownloadManager.addDownload(Torrent, File, File)

addDownload

public Download addDownload(Torrent torrent,
                            java.io.File torrent_file,
                            java.io.File data_location)
                     throws DownloadException
Description copied from interface: DownloadManager
Add a torrent from a "Torrent" object and point it at the data location. The torrent_location should be the location of where the torrent file is on disk. This will be the torrent file that Azureus will use internally. If null is passed, then a file to store the torrent data in will be automatically created by Azureus.

Specified by:
addDownload in interface DownloadManager
Parameters:
torrent - The torrent object to create a download with.
torrent_file - The location of the file on disk - if null, a file to store the torrent data into will be created automatically.
data_location - null -> user default data save location if defined
Returns:
support for null params for torrent_location/data_location since 2.1.0.4
Throws:
DownloadException

addDownload

public Download addDownload(Torrent torrent,
                            java.io.File torrent_file,
                            java.io.File data_location,
                            int initial_state)
                     throws DownloadException
Throws:
DownloadException

addDownloadStopped

public Download addDownloadStopped(Torrent torrent,
                                   java.io.File torrent_location,
                                   java.io.File data_location)
                            throws DownloadException
Description copied from interface: DownloadManager
Explicit way of adding a download in a stopped state

Specified by:
addDownloadStopped in interface DownloadManager
Returns:
Throws:
DownloadException

addNonPersistentDownload

public Download addNonPersistentDownload(Torrent torrent,
                                         java.io.File torrent_file,
                                         java.io.File data_location)
                                  throws DownloadException
Description copied from interface: DownloadManager
Add a non-persistent download. Such downloads are not persisted by Azureus and as such will not be remembered across an Azureus close and restart.

Specified by:
addNonPersistentDownload in interface DownloadManager
Returns:
Throws:
DownloadException

addNonPersistentDownloadStopped

public Download addNonPersistentDownloadStopped(Torrent torrent,
                                                java.io.File torrent_file,
                                                java.io.File data_location)
                                         throws DownloadException
Specified by:
addNonPersistentDownloadStopped in interface DownloadManager
Throws:
DownloadException

clearNonPersistentDownloadState

public void clearNonPersistentDownloadState(byte[] hash)
Description copied from interface: DownloadManager
Although non-persistent downloads themselves aren't rememebered across restarts, some internal stats are (for continuity, like total up/down, file allocation state) - this method allows this to be removed

Specified by:
clearNonPersistentDownloadState in interface DownloadManager

getInitialState

protected int getInitialState()

getDownload

protected DownloadImpl getDownload(DownloadManager dm)
                            throws DownloadException
Throws:
DownloadException

getDownloadStatic

public static DownloadImpl[] getDownloadStatic(DownloadManager[] dm)

getDownloadStatic

public static DownloadImpl getDownloadStatic(DownloadManager dm)
                                      throws DownloadException
Retrieve the plugin Downlaod object related to the DownloadManager

Parameters:
dm - DownloadManager to find
Returns:
plugin object
Throws:
DownloadException

getDownloadStatic

public static Download getDownloadStatic(DiskManager dm)
                                  throws DownloadException
Throws:
DownloadException

getDownload

public Download getDownload(DiskManager dm)
                     throws DownloadException
Throws:
DownloadException

getDownload

protected Download getDownload(TOTorrent torrent)
                        throws DownloadException
Throws:
DownloadException

getDownloadStatic

public static Download getDownloadStatic(TOTorrent torrent)
                                  throws DownloadException
Throws:
DownloadException

getDownload

public Download getDownload(Torrent _torrent)
Description copied from interface: DownloadManager
Gets the download for a particular torrent, returns null if not found

Specified by:
getDownload in interface DownloadManager
Returns:

getDownload

public Download getDownload(byte[] hash)
Description copied from interface: DownloadManager
Gets a download given its hash

Specified by:
getDownload in interface DownloadManager
Returns:

getDownloads

public Download[] getDownloads()
Description copied from interface: DownloadManager
Gets all the downloads. Returned in Download "index" order

Specified by:
getDownloads in interface DownloadManager
Returns:

getDownloads

public Download[] getDownloads(boolean bSorted)
Description copied from interface: DownloadManager
Gets all the downloads.

Specified by:
getDownloads in interface DownloadManager
Parameters:
bSorted - true - Returned in Download "index" order.
false - Order not guaranteed. Faster retrieval.
Returns:
array of Download object

pauseDownloads

public void pauseDownloads()
Description copied from interface: DownloadManager
pause all running downloads

Specified by:
pauseDownloads in interface DownloadManager

canPauseDownloads

public boolean canPauseDownloads()
Specified by:
canPauseDownloads in interface DownloadManager

resumeDownloads

public void resumeDownloads()
Description copied from interface: DownloadManager
resume previously paused downloads

Specified by:
resumeDownloads in interface DownloadManager

canResumeDownloads

public boolean canResumeDownloads()
Specified by:
canResumeDownloads in interface DownloadManager

startAllDownloads

public void startAllDownloads()
Description copied from interface: DownloadManager
starts all non-running downloads

Specified by:
startAllDownloads in interface DownloadManager

stopAllDownloads

public void stopAllDownloads()
Description copied from interface: DownloadManager
stops all running downloads

Specified by:
stopAllDownloads in interface DownloadManager

getStats

public DownloadManagerStats getStats()
Description copied from interface: DownloadManager
Get the download manager statistics

Specified by:
getStats in interface DownloadManager
Returns:

isSeedingOnly

public boolean isSeedingOnly()
Description copied from interface: DownloadManager
indicates whether or not all active downloads are in a seeding (or effective) seeding state

Specified by:
isSeedingOnly in interface DownloadManager
Returns:

addListener

public void addListener(DownloadManagerListener l)
Description copied from interface: DownloadManager
Add a listener that will be informed when a download is added to and removed from Azureus.

Invoking this method is equivalent to addListener(l, true).

Specified by:
addListener in interface DownloadManager
Parameters:
l - The listener to add.
See Also:
DownloadManager.addListener(DownloadManagerListener, boolean)

addListener

public void addListener(DownloadManagerListener l,
                        boolean notify_of_current_downloads)
Description copied from interface: DownloadManager
Add a listener that will be informed when a download is added to and removed from Azureus.

Specified by:
addListener in interface DownloadManager
Parameters:
l - The listener to add.
notify_of_current_downloads - true - if you want the listener to have its downloadAdded method invoked immediately with all downloads currently managed by Azureus. false - if you only want to be notified about new downloads added after this method is called.

removeListener

public void removeListener(DownloadManagerListener l)
Description copied from interface: DownloadManager
Removes a previously added listener.

Invoking this method is equivalent to removeListener(l, false).

Specified by:
removeListener in interface DownloadManager
Parameters:
l - The listener to remove.
See Also:
DownloadManager.removeListener(DownloadManagerListener, boolean)

removeListener

public void removeListener(DownloadManagerListener l,
                           boolean notify_of_current_downloads)
Description copied from interface: DownloadManager
Removes a previously added listener.

Specified by:
removeListener in interface DownloadManager
Parameters:
l - The listener to remove.
notify_of_current_downloads - true - if you want the listener to have its downloadRemoved method invoked immediately with all downloads currently managed by Azureus, false otherwise.

initialised

public void initialised(DownloadManager manager,
                        boolean for_seeding)
Specified by:
initialised in interface DownloadManagerInitialisationAdapter

getActions

public int getActions()
Description copied from interface: DownloadManagerInitialisationAdapter
Unfortuately order can be important when firing off initialisation adapters, in particular if one listener assigns tags to a download it needs to do this before any other listeners that might process a download's tags

Specified by:
getActions in interface DownloadManagerInitialisationAdapter
Returns:

addDownloadWillBeAddedListener

public void addDownloadWillBeAddedListener(DownloadWillBeAddedListener listener)
Specified by:
addDownloadWillBeAddedListener in interface DownloadManager

removeDownloadWillBeAddedListener

public void removeDownloadWillBeAddedListener(DownloadWillBeAddedListener listener)
Specified by:
removeDownloadWillBeAddedListener in interface DownloadManager

addExternalDownload

public void addExternalDownload(Download download)

removeExternalDownload

public void removeExternalDownload(Download download)

getGlobalDownloadEventNotifier

public DownloadEventNotifier getGlobalDownloadEventNotifier()
Description copied from interface: DownloadManager
Return a DownloadEventNotifier object which can be used as an easy way to register listeners against all downloads handled by Azureus.

Specified by:
getGlobalDownloadEventNotifier in interface DownloadManager

setSaveLocationManager

public void setSaveLocationManager(SaveLocationManager manager)
Description copied from interface: DownloadManager
Registers an object to be in control of determining the default save location for downloads. You can set it to null to remove any object which was previously set.

By default, Azureus will use its default save location manager which handles on-completion and on-removal events.

Specified by:
setSaveLocationManager in interface DownloadManager
Parameters:
manager - The new manager object to use.

getSaveLocationManager

public SaveLocationManager getSaveLocationManager()
Description copied from interface: DownloadManager
Returns the current SaveLocationManager object which decides where downloads should be placed.

Specified by:
getSaveLocationManager in interface DownloadManager
Returns:
The manager object currently in use.

getDefaultSaveLocationManager

public DefaultSaveLocationManager getDefaultSaveLocationManager()
Description copied from interface: DownloadManager
Returns the default SaveLocationManager object that controls where downloads should be placed.

Specified by:
getDefaultSaveLocationManager in interface DownloadManager
Returns:
The default save location manager object.

canStubbify

public boolean canStubbify(DownloadImpl download)

stubbify

protected DownloadStub stubbify(DownloadImpl download)
                         throws DownloadException,
                                DownloadRemovalVetoException
Throws:
DownloadException
DownloadRemovalVetoException

destubbify

protected Download destubbify(DownloadStubImpl stub)
                       throws DownloadException
Throws:
DownloadException

remove

protected void remove(DownloadStubImpl stub)

getStubTorrent

public static TOTorrent getStubTorrent(byte[] hash)

getTorrent

protected TOTorrent getTorrent(DownloadStubImpl stub)

updated

protected void updated(DownloadStubImpl stub)

getDownloadStubs

public DownloadStub[] getDownloadStubs()
Specified by:
getDownloadStubs in interface DownloadManager

getDownloadStubCount

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

lookupDownloadStub

public DownloadStub lookupDownloadStub(byte[] hash)
Specified by:
lookupDownloadStub in interface DownloadManager

addDownloadStubListener

public void addDownloadStubListener(DownloadStubListener l,
                                    boolean inform_of_current)
Specified by:
addDownloadStubListener in interface DownloadManager

removeDownloadStubListener

public void removeDownloadStubListener(DownloadStubListener l)
Specified by:
removeDownloadStubListener in interface DownloadManager