Class DownloadManagerImpl
java.lang.Object
com.biglybt.pifimpl.local.download.DownloadManagerImpl
- All Implemented Interfaces:
DownloadManagerInitialisationAdapter, DownloadManager
public class DownloadManagerImpl
extends Object
implements DownloadManager, DownloadManagerInitialisationAdapter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Fileprotected static AEMonitorprivate FrequencyLimitedDispatcherprivate booleanprivate Map<DownloadManager, DownloadImpl> private CopyOnWriteList<DownloadStubListener> private ByteArrayHashMap<DownloadStubImpl> private List<DownloadStubImpl> private final DownloadEventNotifierImplprivate final GlobalManagerprivate Set<DownloadStub> private List<DownloadManagerListener> private AEMonitorprivate Map<DownloadManager, DownloadImpl> protected static DownloadManagerImplprivate final DownloadManagerStatsprivate static final Stringprivate final TagManagerFields inherited from interface DownloadManagerInitialisationAdapter
ACT_ASSIGNS_TAGS, ACT_NONE, ACT_PROCESSES_TAGS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDownload(Torrent torrent) Add a torrent from a "Torrent" object.addDownload(Torrent torrent, File torrent_file, File data_location) Add a torrent from a "Torrent" object and point it at the data location.addDownload(Torrent torrent, File torrent_file, File data_location, int initial_state) voidaddDownload(File fileName) Add a torrent from a file.voidaddDownload(URL url) add a torrent from a URL.voidaddDownload(URL url, boolean auto_download) Add a torrent from a URL with explicit auto-download optionvoidaddDownload(URL url, URL referrer) add a torrent from a URL.voidaddDownload(URL url, URL referrer, boolean auto_download, Map request_properties) voidaddDownload(URL url, Map request_properties) add a torrent from a URL and use the supplied request propertiesprotected voidaddDownloadStopped(Torrent torrent, File torrent_location, File data_location) Explicit way of adding a download in a stopped statevoidaddDownloadStubListener(DownloadStubListener l, boolean inform_of_current) voidvoidAdd a listener that will be informed when a download is added to and removed from the client.voidaddListener(DownloadManagerListener l, boolean notify_of_current_downloads) Add a listener that will be informed when a download is added to and removed from the client.addNonPersistentDownload(Torrent torrent, File torrent_file, File data_location) Add a non-persistent download.addNonPersistentDownloadStopped(Torrent torrent, File torrent_file, File data_location) booleanbooleanbooleancanStubbify(DownloadImpl download) voidclearNonPersistentDownloadState(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 removedprotected Downloaddestubbify(DownloadStubImpl stub) intUnfortuately 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 tagsReturns the defaultSaveLocationManagerobject that controls where downloads should be placed.getDownload(byte[] hash, boolean check_truncated) protected DownloadImplprotected DownloadgetDownload(TOTorrent torrent) getDownload(Torrent _torrent) Gets the download for a particular torrent, returns null if not foundDownload[]Gets all the downloads.Download[]getDownloads(boolean bSorted) Gets all the downloads.static Downloadstatic DownloadImplRetrieve the plugin Downlaod object related to the DownloadManagerstatic DownloadImpl[]static DownloadgetDownloadStatic(TOTorrent torrent) intReturn aDownloadEventNotifierobject which can be used as an easy way to register listeners against all downloads handled by the client.protected intReturns the currentSaveLocationManagerobject which decides where downloads should be placed.static DownloadManagerImplgetSingleton(Core core) getStats()Get the download manager statisticsstatic TOTorrentgetStubTorrent(byte[] hash) protected TOTorrentgetTorrent(DownloadStubImpl stub) private voidinformAdded(DownloadStub stub, boolean preparing) private voidinformRemoved(DownloadStub stub, boolean preparing) voidinitialised(DownloadManager manager, boolean for_seeding) booleanindicates whether or not all active downloads are in a seeding (or effective) seeding statelookupDownloadStub(byte[] hash) voidpause all running downloadsprivate voidprotected voidremove(DownloadStubImpl stub) voidvoidvoidRemoves a previously added listener.voidremoveListener(DownloadManagerListener l, boolean notify_of_current_downloads) Removes a previously added listener.voidresume previously paused downloadsvoidRegisters an object to be in control of determining the default save location for downloads.voidstarts all non-running downloadsvoidstops all running downloadsprotected DownloadStubstubbify(DownloadImpl download) protected voidupdated(DownloadStubImpl stub) private voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DownloadManager
getDownload
-
Field Details
-
singleton
-
class_mon
-
global_manager
-
stats
-
global_dl_notifier
-
tag_manager
-
listeners
-
dwba_listeners
-
listeners_mon
-
pending_dls
-
download_map
-
STUB_CONFIG_FILE
- See Also:
-
ARCHIVE_DIR
-
download_stubs
-
download_stub_map
-
download_stub_listeners
-
dirty_stub_dispatcher
-
dirty_stubs
private boolean dirty_stubs -
informing_of_add
-
-
Constructor Details
-
DownloadManagerImpl
-
-
Method Details
-
getSingleton
-
addDownload
Description copied from interface:DownloadManagerAdd 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:
addDownloadin interfaceDownloadManager- Parameters:
fileName-- See Also:
-
addDownload
Description copied from interface:DownloadManageradd 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:
addDownloadin interfaceDownloadManager- Parameters:
url-
-
addDownload
Description copied from interface:DownloadManagerAdd a torrent from a URL with explicit auto-download option- Specified by:
addDownloadin interfaceDownloadManager- Parameters:
url-auto_download-- Throws:
DownloadException
-
addDownload
Description copied from interface:DownloadManageradd 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:
addDownloadin interfaceDownloadManager- Parameters:
url-referrer-
-
addDownload
Description copied from interface:DownloadManageradd a torrent from a URL and use the supplied request properties- Specified by:
addDownloadin interfaceDownloadManager- Parameters:
url-request_properties-
-
addDownload
-
addDownloadManager
-
addDownload
Description copied from interface:DownloadManagerAdd 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 theaddDownload(Torrent, File, File)method.- Specified by:
addDownloadin interfaceDownloadManager- Parameters:
torrent-- Returns:
- Throws:
DownloadException- See Also:
-
addDownload
public Download addDownload(Torrent torrent, File torrent_file, File data_location) throws DownloadException Description copied from interface:DownloadManagerAdd 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 the client will use internally. If null is passed, then a file to store the torrent data in will be automatically created by the client.- Specified by:
addDownloadin interfaceDownloadManager- Parameters:
torrent- The torrent object to create a download with.torrent_file- The location of the file on disk - ifnull, 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, File torrent_file, File data_location, int initial_state) throws DownloadException - Throws:
DownloadException
-
addDownloadStopped
public Download addDownloadStopped(Torrent torrent, File torrent_location, File data_location) throws DownloadException Description copied from interface:DownloadManagerExplicit way of adding a download in a stopped state- Specified by:
addDownloadStoppedin interfaceDownloadManager- Parameters:
torrent-torrent_location-data_location-- Returns:
- Throws:
DownloadException
-
addNonPersistentDownload
public Download addNonPersistentDownload(Torrent torrent, File torrent_file, File data_location) throws DownloadException Description copied from interface:DownloadManagerAdd a non-persistent download. Such downloads are not persisted by the client and as such will not be remembered across an client close and restart.- Specified by:
addNonPersistentDownloadin interfaceDownloadManager- Parameters:
torrent-torrent_file-data_location-- Returns:
- Throws:
DownloadException
-
addNonPersistentDownloadStopped
public Download addNonPersistentDownloadStopped(Torrent torrent, File torrent_file, File data_location) throws DownloadException - Specified by:
addNonPersistentDownloadStoppedin interfaceDownloadManager- Throws:
DownloadException
-
clearNonPersistentDownloadState
public void clearNonPersistentDownloadState(byte[] hash) Description copied from interface:DownloadManagerAlthough 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:
clearNonPersistentDownloadStatein interfaceDownloadManager- Parameters:
hash-
-
getInitialState
protected int getInitialState() -
getDownload
- Throws:
DownloadException
-
getDownloadStatic
-
getDownloadStatic
Retrieve the plugin Downlaod object related to the DownloadManager- Parameters:
dm- DownloadManager to find- Returns:
- plugin object
- Throws:
DownloadException
-
getDownloadStatic
- Throws:
DownloadException
-
getDownload
- Throws:
DownloadException
-
getDownload
- Throws:
DownloadException
-
getDownloadStatic
- Throws:
DownloadException
-
getDownload
Description copied from interface:DownloadManagerGets the download for a particular torrent, returns null if not found- Specified by:
getDownloadin interfaceDownloadManager- Parameters:
_torrent-- Returns:
-
getDownload
- Specified by:
getDownloadin interfaceDownloadManager
-
getDownloads
Description copied from interface:DownloadManagerGets all the downloads. Returned in Download "index" order- Specified by:
getDownloadsin interfaceDownloadManager- Returns:
-
getDownloads
Description copied from interface:DownloadManagerGets all the downloads.- Specified by:
getDownloadsin interfaceDownloadManager- 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:DownloadManagerpause all running downloads- Specified by:
pauseDownloadsin interfaceDownloadManager
-
canPauseDownloads
public boolean canPauseDownloads()- Specified by:
canPauseDownloadsin interfaceDownloadManager
-
resumeDownloads
public void resumeDownloads()Description copied from interface:DownloadManagerresume previously paused downloads- Specified by:
resumeDownloadsin interfaceDownloadManager
-
canResumeDownloads
public boolean canResumeDownloads()- Specified by:
canResumeDownloadsin interfaceDownloadManager
-
startAllDownloads
public void startAllDownloads()Description copied from interface:DownloadManagerstarts all non-running downloads- Specified by:
startAllDownloadsin interfaceDownloadManager
-
stopAllDownloads
public void stopAllDownloads()Description copied from interface:DownloadManagerstops all running downloads- Specified by:
stopAllDownloadsin interfaceDownloadManager
-
getStats
Description copied from interface:DownloadManagerGet the download manager statistics- Specified by:
getStatsin interfaceDownloadManager- Returns:
-
isSeedingOnly
public boolean isSeedingOnly()Description copied from interface:DownloadManagerindicates whether or not all active downloads are in a seeding (or effective) seeding state- Specified by:
isSeedingOnlyin interfaceDownloadManager- Returns:
-
addListener
Description copied from interface:DownloadManagerAdd a listener that will be informed when a download is added to and removed from the client. Invoking this method is equivalent toaddListener(l, true).- Specified by:
addListenerin interfaceDownloadManager- Parameters:
l- The listener to add.- See Also:
-
addListener
Description copied from interface:DownloadManagerAdd a listener that will be informed when a download is added to and removed from the client.- Specified by:
addListenerin interfaceDownloadManager- Parameters:
l- The listener to add.notify_of_current_downloads- true - if you want the listener to have itsdownloadAddedmethod invoked immediately with all downloads currently managed by the client. false - if you only want to be notified about new downloads added after this method is called.
-
removeListener
Description copied from interface:DownloadManagerRemoves a previously added listener. Invoking this method is equivalent toremoveListener(l, false).- Specified by:
removeListenerin interfaceDownloadManager- Parameters:
l- The listener to remove.- See Also:
-
removeListener
Description copied from interface:DownloadManagerRemoves a previously added listener.- Specified by:
removeListenerin interfaceDownloadManager- Parameters:
l- The listener to remove.notify_of_current_downloads- true - if you want the listener to have itsdownloadRemovedmethod invoked immediately with all downloads currently managed by the client, false otherwise.
-
initialised
- Specified by:
initialisedin interfaceDownloadManagerInitialisationAdapter
-
getActions
public int getActions()Description copied from interface:DownloadManagerInitialisationAdapterUnfortuately 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:
getActionsin interfaceDownloadManagerInitialisationAdapter- Returns:
-
addDownloadWillBeAddedListener
- Specified by:
addDownloadWillBeAddedListenerin interfaceDownloadManager
-
removeDownloadWillBeAddedListener
- Specified by:
removeDownloadWillBeAddedListenerin interfaceDownloadManager
-
getGlobalDownloadEventNotifier
Description copied from interface:DownloadManagerReturn aDownloadEventNotifierobject which can be used as an easy way to register listeners against all downloads handled by the client.- Specified by:
getGlobalDownloadEventNotifierin interfaceDownloadManager
-
setSaveLocationManager
Description copied from interface:DownloadManagerRegisters 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, the client will use its default save location manager which handles on-completion and on-removal events.
- Specified by:
setSaveLocationManagerin interfaceDownloadManager- Parameters:
manager- The new manager object to use.
-
getSaveLocationManager
Description copied from interface:DownloadManagerReturns the currentSaveLocationManagerobject which decides where downloads should be placed.- Specified by:
getSaveLocationManagerin interfaceDownloadManager- Returns:
- The manager object currently in use.
-
getDefaultSaveLocationManager
Description copied from interface:DownloadManagerReturns the defaultSaveLocationManagerobject that controls where downloads should be placed.- Specified by:
getDefaultSaveLocationManagerin interfaceDownloadManager- Returns:
- The default save location manager object.
-
readStubConfig
private void readStubConfig() -
writeStubConfig
private void writeStubConfig() -
canStubbify
-
stubbify
protected DownloadStub stubbify(DownloadImpl download) throws DownloadException, DownloadRemovalVetoException -
destubbify
- Throws:
DownloadException
-
remove
-
getStubTorrent
-
getTorrent
-
updated
-
getDownloadStubs
- Specified by:
getDownloadStubsin interfaceDownloadManager
-
getDownloadStubCount
public int getDownloadStubCount()- Specified by:
getDownloadStubCountin interfaceDownloadManager
-
lookupDownloadStub
- Specified by:
lookupDownloadStubin interfaceDownloadManager
-
informAdded
-
informRemoved
-
addDownloadStubListener
- Specified by:
addDownloadStubListenerin interfaceDownloadManager
-
removeDownloadStubListener
- Specified by:
removeDownloadStubListenerin interfaceDownloadManager
-