Interface DownloadManager
- All Known Implementing Classes:
DownloadManagerImpl
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final Objectstatic final Objectstatic final Objectstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from interface Taggable
TT_DOWNLOAD, TT_NONE, TT_PEER -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddDiskListener(DownloadManagerDiskListener listener) voidaddListener(DownloadManagerListener listener) voidaddListener(DownloadManagerListener listener, boolean triggerStateChange) voidaddPeerListener(DownloadManagerPeerListener listener) voidaddPeerListener(DownloadManagerPeerListener listener, boolean bDispatchForExisting) voidaddPieceListener(DownloadManagerPieceListener listener) voidaddPieceListener(DownloadManagerPieceListener listener, boolean bDispatchForExisting) voidaddRateLimiter(LimitedRateGroup group, boolean upload) voidaddTPSListener(DownloadManagerTPSListener listener) voidbooleanbooleanbooleanvoidcheckLightSeeding(boolean full_sync) voidcopyDataFiles(File parent_dir, CoreOperationTask.ProgressCallback progress) voiddestroy(boolean is_duplicate) Indicates that the download manager is no longer neededvoidexportDownload(File parent_dir) default booleanfilesExist(boolean expected_to_be_allocated) Checks if all the files the user wants to download from this torrent actually exist on their filesystem.booleanfilesExist(boolean expected_to_be_allocated, boolean test_only) default voidfireGlobalManagerEvent(int event_type) voidfireGlobalManagerEvent(int event_type, Object event_data) voidvoidgenerateEvidence(IndentWriter writer, boolean full) Returns the file location where we save the torrent, this includes the parent directory and the actual file name.intbooleanRetrieve whether this download is assumed complete.longlonggives the time this download was created (not the torrent but the download itself)intPEPeer[]PEPiece[]Deprecated.use getDiskManagerFileInfoSet() insteadintReturns the max uploads depending on whether the download is seeding and it has a separate rate for thisintintreturns the currently in force upload speed limit which may vary from the stats.intintintintreturns a name based on the torrent hash or an empty string if torrent invalidintlong[]Progress of a move operationObject[]See plugin ConnectionManager.NAT_ constants for return valuesintintintintintgetRateLimiters(boolean upload) longgetSize()intgetState()getStats()int[]getStorageType(DiskManagerFileInfo[] infos) intFor stopping this returns the target state after stopping (stopped/queued)intlongThis includes the full path to the torrent file.intWhen the next call to the tracker will occur (in seconds)getUserData(Object key) To retreive arbitrary objects against this object.voidvoidbooleanbooleanDetermine whether disk allocation has already been done.booleanbooleanisDownloadComplete(boolean bIncludingDND) Retrieves whether the download is completebooleanbooleanbooleanReturns true if the download is being saved to one of the default save directories.default booleanbooleanisPaused()booleanbooleanbooleanbooleanvoidmoveDataFiles(File new_parent_dir) Move data files to new location.voidmoveDataFiles(File new_parent_dir, String new_name) Move the files and rename a download in one go.voidmoveDataFilesLive(File new_parent_dir) At some point someone made the file-move operations stop+restart the download when it was designed to work without doing this (see move-on-complete for example).voidmoveTorrentFile(File new_parent_dir) Move torrent file to new location.voidmoveTorrentFile(File parent_dir, String new_name) booleanpause(boolean only_if_active) booleanpause(boolean only_if_active, long auto_resume_time) voidRecheck a particular file.voidvoidvoidremoveListener(DownloadManagerListener listener) voidvoidvoidremoveRateLimiter(LimitedRateGroup group, boolean upload) voidremoveTPSListener(DownloadManagerTPSListener listener) voidvoidRenames the save file, torrent file and the displayed name.voidrenameDownload(String new_name) Rename the download - this means the name of the file being downloaded (for single file torrents), or the name of the directory holding the files (in a multi-file torrent).voidrenameTorrent(String new_name) voidrenameTorrentSafe(String name) Same as renameTorrent, but appends numbers if torrent already existsvoidrequestAllocation(List<DiskManagerFileInfo> files) Instructions that file given files need allocation - used when switching file storage types/skipped state Will pause and resume the download if it is activebooleanWill set this download to be "assumed complete" for if the download is already complete (excluding DND)voidvoidrequestTrackerAnnounce(boolean immediate) voidrequestTrackerScrape(boolean immediate) voidresetFile(DiskManagerFileInfo file) Reset the file download state to totally undownloaded.voidresume()booleanresume(int target_state) resume the download and wait until it reaches the target state.voidsaveDownload(boolean interim) persist any general download related information, excluding resume data which is managed separately by saveResumeDatavoidpersist resume databooleanGives the download an opportunity to schedule seeding mode piece rechecks if desiredvoiddefault voidsetAutoResumeTime(long time) voidvoidsetCreationTime(long t) voidsetCryptoLevel(int level) voidsetDataAlreadyAllocated(boolean already_allocated) Set whether data allocation has already been done, so we know when to allocate and when to throw a missing-data error message.voidsetErrorState(int errorType, String errorDetails, int errorFlags) Download must be stopped - used at start-of-day to recover error statevoidsetForceStart(boolean forceStart) voidsetMaxUploads(int max_slots) voidsetPieceCheckingEnabled(boolean enabled) Use with care - introduced to support speed tests whereby we want to avoid checking the virtual torrent used for the testvoidsetPosition(int newPosition) voidsetQueueReason(String reason) voidsetScrapeResult(DownloadScrapeResult result) voidvoidsetStartReason(String reason) voidvoidvoidsetStopReason(String reason) voidsetTorrentFile(File new_parent_dir, String new_name) Sets the torrent file name (will perform a move of the torrent file) - this shouldn't be used unless you know what you are doing (it requires the download to be stopped!) - it is safer to use moveTorrentFile instead.voidsetTorrentFileName(String string) voidsetTorrentSaveDir(File _new_location, boolean locationIncludesName) changes the save directory.default voidsetTorrentSaveDir(String sPath) Deprecated.Use setTorrentSaveDir(FileUtil.newFile(sPath), false)voidvoidsetUserData(Object key, Object value) To store arbitrary objects against this object.voidvoidstopIt(int stateAfterStopping, boolean remove_torrent, boolean remove_data) Stop the download manager, and do any file/torrent removals.voidstopIt(int stateAfterStopping, boolean remove_torrent, boolean remove_data, boolean for_removal) As above but definitely indicates that the stop is for removal (if for_removal is true) and therefore that any removal specific actions such as removing partial files should be performedbooleanvoidCalled for certain config change events so that individual managers don't have to separately listener for changesvoidupdateAutoUploadPriority(Object key, boolean inc) Methods inherited from interface Taggable
getTaggableID, getTaggableName, getTaggableResolver, getTaggableTransientProperty, getTaggableType, getTagMutationCount, setTaggableTransientProperty, updateTagMutationCount
-
Field Details
-
STATE_START_OF_DAY
static final int STATE_START_OF_DAY- See Also:
-
STATE_WAITING
static final int STATE_WAITING- See Also:
-
STATE_INITIALIZING
static final int STATE_INITIALIZING- See Also:
-
STATE_INITIALIZED
static final int STATE_INITIALIZED- See Also:
-
STATE_ALLOCATING
static final int STATE_ALLOCATING- See Also:
-
STATE_CHECKING
static final int STATE_CHECKING- See Also:
-
STATE_READY
static final int STATE_READY- See Also:
-
STATE_DOWNLOADING
static final int STATE_DOWNLOADING- See Also:
-
STATE_FINISHING
static final int STATE_FINISHING- See Also:
-
STATE_SEEDING
static final int STATE_SEEDING- See Also:
-
STATE_STOPPING
static final int STATE_STOPPING- See Also:
-
STATE_STOPPED
static final int STATE_STOPPED- See Also:
-
STATE_CLOSED
static final int STATE_CLOSED- See Also:
-
STATE_QUEUED
static final int STATE_QUEUED- See Also:
-
STATE_ERROR
static final int STATE_ERROR- See Also:
-
WEALTH_STOPPED
static final int WEALTH_STOPPED- See Also:
-
WEALTH_NO_TRACKER
static final int WEALTH_NO_TRACKER- See Also:
-
WEALTH_NO_REMOTE
static final int WEALTH_NO_REMOTE- See Also:
-
WEALTH_OK
static final int WEALTH_OK- See Also:
-
WEALTH_KO
static final int WEALTH_KO- See Also:
-
WEALTH_ERROR
static final int WEALTH_ERROR- See Also:
-
ET_NONE
static final int ET_NONE- See Also:
-
ET_OTHER
static final int ET_OTHER- See Also:
-
ET_INSUFFICIENT_SPACE
static final int ET_INSUFFICIENT_SPACE- See Also:
-
ET_STOP_DURING_INIT
static final int ET_STOP_DURING_INIT- See Also:
-
ET_FILE_MISSING
static final int ET_FILE_MISSING- See Also:
-
EF_WAS_FORCE_START
static final int EF_WAS_FORCE_START- See Also:
-
UD_KEY_START_REASON
-
UD_KEY_QUEUE_REASON
-
UD_KEY_STOP_REASON
-
-
Method Details
-
setConstructed
void setConstructed() -
isConstructed
boolean isConstructed() -
initialize
void initialize() -
getState
int getState() -
getSubState
int getSubState()For stopping this returns the target state after stopping (stopped/queued)- Returns:
-
setStateWaiting
void setStateWaiting() -
setStateQueued
void setStateQueued() -
startDownload
void startDownload() -
canForceRecheck
boolean canForceRecheck() -
isForceRechecking
boolean isForceRechecking() -
forceRecheck
void forceRecheck() -
syncGlobalConfig
void syncGlobalConfig()Called for certain config change events so that individual managers don't have to separately listener for changes -
resetFile
Reset the file download state to totally undownloaded. Download must be stopped- Parameters:
file-
-
recheckFile
Recheck a particular file. Download must be stopped- Parameters:
file-
-
requestAllocation
Instructions that file given files need allocation - used when switching file storage types/skipped state Will pause and resume the download if it is active- Parameters:
files-
-
setPieceCheckingEnabled
void setPieceCheckingEnabled(boolean enabled) Use with care - introduced to support speed tests whereby we want to avoid checking the virtual torrent used for the test- Parameters:
enabled-
-
stopIt
void stopIt(int stateAfterStopping, boolean remove_torrent, boolean remove_data) Stop the download manager, and do any file/torrent removals.- Parameters:
stateAfterStopping-remove_torrent- remove the .torrent file after stoppingremove_data- remove the data file after stopping
-
setStartReason
-
getStartReason
String getStartReason() -
setStopReason
-
getStopReason
String getStopReason() -
setQueueReason
-
getQueueReason
String getQueueReason() -
stopIt
void stopIt(int stateAfterStopping, boolean remove_torrent, boolean remove_data, boolean for_removal) As above but definitely indicates that the stop is for removal (if for_removal is true) and therefore that any removal specific actions such as removing partial files should be performed- Parameters:
stateAfterStopping-remove_torrent-remove_data-for_removal-
-
pause
boolean pause(boolean only_if_active) - Parameters:
only_if_active-- Returns:
- true -> download was placed into a paused state (including if it was already paused)
-
pause
boolean pause(boolean only_if_active, long auto_resume_time) - Parameters:
auto_resume_time-- Returns:
- true -> download was placed into a paused state (including if it was already paused)
-
isPaused
boolean isPaused() -
stopPausedDownload
boolean stopPausedDownload() -
resume
void resume() -
resume
boolean resume(int target_state) resume the download and wait until it reaches the target state. It may fail to reach this state (e.g. goes into an error state). It will however block if it looks like progress towards the state is being made (allocating/checking)- Parameters:
target_state-- Returns:
- whether or not the state was reached
-
getTCPListeningPortNumber
int getTCPListeningPortNumber() -
getAutoResumeTime
long getAutoResumeTime() -
setAutoResumeTime
default void setAutoResumeTime(long time) -
getGlobalManager
GlobalManager getGlobalManager() -
getDiskManager
DiskManager getDiskManager() -
getDiskManagerPiecesSnapshot
DiskManagerPiece[] getDiskManagerPiecesSnapshot() -
getDiskManagerFileInfo
DiskManagerFileInfo[] getDiskManagerFileInfo()Deprecated.use getDiskManagerFileInfoSet() instead -
getDiskManagerFileInfoSet
DiskManagerFileInfoSet getDiskManagerFileInfoSet() -
getNumFileInfos
int getNumFileInfos() -
getPeerManager
PEPeerManager getPeerManager() -
getDownloadState
DownloadManagerState getDownloadState() -
getTorrent
TOTorrent getTorrent() -
getTrackerClient
TRTrackerAnnouncer getTrackerClient() -
requestTrackerAnnounce
void requestTrackerAnnounce(boolean immediate) -
requestTrackerScrape
void requestTrackerScrape(boolean immediate) -
getTrackerScrapeResponse
TRTrackerScraperResponse getTrackerScrapeResponse() -
getGoodTrackerScrapeResponses
List<TRTrackerScraperResponse> getGoodTrackerScrapeResponses() -
setTrackerScrapeResponse
-
getDisplayName
String getDisplayName() -
getInternalName
String getInternalName()returns a name based on the torrent hash or an empty string if torrent invalid- Returns:
-
getSize
long getSize() -
getTorrentFileName
-
setTorrentFileName
-
getAbsoluteSaveLocation
File getAbsoluteSaveLocation()Returns the file location where we save the torrent, this includes the parent directory and the actual file name. -
getSaveLocation
File getSaveLocation() -
setTorrentSaveDir
Deprecated.Use setTorrentSaveDir(FileUtil.newFile(sPath), false) -
setTorrentSaveDir
changes the save directory. Only call this if you know what you are doing!!!! When locationIncludesName, torrent name will also change (Data files will be stored under new_location)
When !locationIncludesName, only save dire is changed, name remains (Data files will be stored under new_location + / + old_location.getName()) -
isForceStart
boolean isForceStart() -
setForceStart
void setForceStart(boolean forceStart) -
isPersistent
boolean isPersistent() -
isDownloadComplete
boolean isDownloadComplete(boolean bIncludingDND) Retrieves whether the download is complete- Parameters:
bIncludingDND- true- include files marked as Do Not Download.
false- don't include files marked DND.If there are DND files and you choose to include DND in the calculation, false will always be returned.
- Returns:
- whether download is complete
-
checkLightSeeding
void checkLightSeeding(boolean full_sync) -
getTrackerStatus
String getTrackerStatus() -
getTrackerTime
int getTrackerTime()When the next call to the tracker will occur (in seconds) -
getTorrentComment
String getTorrentComment() -
getTorrentCreatedBy
String getTorrentCreatedBy() -
getTorrentCreationDate
long getTorrentCreationDate() -
getNbPieces
int getNbPieces() -
getPieceLength
String getPieceLength() -
getNbSeeds
int getNbSeeds() -
getNbPeers
int getNbPeers() -
filesExist
default boolean filesExist(boolean expected_to_be_allocated) Checks if all the files the user wants to download from this torrent actually exist on their filesystem.If a file does not exist, the download will be set to error state.
- Parameters:
expected_to_be_allocated- if this is false and allocation hasn't been attempted then the method will return with false without marking the download as in an error state- Returns:
- Whether all the non-skipped (non-DND) files exist
-
filesExist
boolean filesExist(boolean expected_to_be_allocated, boolean test_only) -
isMetadataDownload
default boolean isMetadataDownload() -
setErrorState
Download must be stopped - used at start-of-day to recover error state- Parameters:
errorType-errorDetails-
-
getErrorDetails
String getErrorDetails() -
getErrorType
int getErrorType() -
getErrorFlags
int getErrorFlags() -
getStats
DownloadManagerStats getStats() -
getPosition
int getPosition() -
setPosition
void setPosition(int newPosition) -
getAssumedComplete
boolean getAssumedComplete()Retrieve whether this download is assumed complete.Assumed complete status is kept while the torrent is in a non-running state, even if it has no data.
When the torrent starts up, the real complete level will be checked, and if the torrent actually does have missing data, the download will be thrown into error state.
Only a forced-recheck should clear this flag.
-
requestAssumedCompleteMode
boolean requestAssumedCompleteMode()Will set this download to be "assumed complete" for if the download is already complete (excluding DND)- Returns:
- true- success; false- failure, download not complete
-
getHealthStatus
int getHealthStatus()- Returns:
- the wealthy status of this download
-
getNATStatus
-
saveResumeData
void saveResumeData()persist resume data -
saveDownload
void saveDownload(boolean interim) persist any general download related information, excluding resume data which is managed separately by saveResumeData -
getUserData
-
setUserData
-
isDataAlreadyAllocated
boolean isDataAlreadyAllocated()Determine whether disk allocation has already been done. Used for checking if data is missing on a previously-loaded torrent.- Returns:
- true if data files have already been allocated
-
setDataAlreadyAllocated
void setDataAlreadyAllocated(boolean already_allocated) Set whether data allocation has already been done, so we know when to allocate and when to throw a missing-data error message.- Parameters:
already_allocated-
-
setSeedingRank
-
getSeedingRank
Download.SeedingRank getSeedingRank() -
isSwarmMerging
boolean isSwarmMerging() -
getSwarmMergingInfo
String getSwarmMergingInfo() -
setMaxUploads
void setMaxUploads(int max_slots) -
getMaxUploads
int getMaxUploads() -
updateAutoUploadPriority
-
getEffectiveUploadPriority
int getEffectiveUploadPriority() -
getEffectiveMaxUploads
int getEffectiveMaxUploads()Returns the max uploads depending on whether the download is seeding and it has a separate rate for this- Returns:
-
getEffectiveUploadRateLimitBytesPerSecond
int getEffectiveUploadRateLimitBytesPerSecond()returns the currently in force upload speed limit which may vary from the stats. value as this gives the fixed per-torrent limit- Returns:
-
setCryptoLevel
void setCryptoLevel(int level) -
getCryptoLevel
int getCryptoLevel() -
getMoveProgress
long[] getMoveProgress()Progress of a move operation- Returns:
- null: not moving otherwise [ 0->1000, size ]
-
moveDataFiles
Move data files to new location. Torrent must be in stopped/error state- Parameters:
new_parent_dir-- Throws:
DownloadManagerException
-
moveDataFilesLive
At some point someone made the file-move operations stop+restart the download when it was designed to work without doing this (see move-on-complete for example). As I don't know the reason for this change I've (parg) added a new method to do this in the hope that we might in time migrate back to the 'proper' behaviour. grrr- Parameters:
new_parent_dir-- Throws:
DownloadManagerException
-
copyDataFiles
void copyDataFiles(File parent_dir, CoreOperationTask.ProgressCallback progress) throws DownloadManagerException - Throws:
DownloadManagerException
-
renameDownload
Rename the download - this means the name of the file being downloaded (for single file torrents), or the name of the directory holding the files (in a multi-file torrent). This does not alter the displayed name of the download.- Parameters:
new_name-- Throws:
DownloadManagerException
-
moveDataFiles
Move the files and rename a download in one go. For convenience - either argument can be null, but not both.- Parameters:
new_parent_dir- new location to move torrent data files to. If null, and simple torrent, torrent data file will be renamed new_name. If null, and not simple torrent, torrent end path will be changed to new_name.new_name- For simple torrent, changes the filename of the downloaded file. For non-simple torrent, changes the end path for the downloaded files. If null, torrent data files will be moved to new_parent_dir, with a subfolder of the existing name.- Throws:
DownloadManagerException- See Also:
-
moveTorrentFile
Move torrent file to new location. Download must be stopped/error- Parameters:
new_parent_dir-- Throws:
DownloadManagerException
-
isInDefaultSaveDir
boolean isInDefaultSaveDir()Returns true if the download is being saved to one of the default save directories.- Since:
- 2.5.0.2
-
getCreationTime
long getCreationTime()gives the time this download was created (not the torrent but the download itself)- Returns:
-
setCreationTime
void setCreationTime(long t) -
setAnnounceResult
-
setScrapeResult
-
isUnauthorisedOnTracker
boolean isUnauthorisedOnTracker() -
isTrackerError
boolean isTrackerError() -
getExtendedMessagingMode
int getExtendedMessagingMode()- Returns:
- messaging mode = az, lt or bt
-
destroy
void destroy(boolean is_duplicate) Indicates that the download manager is no longer needed- Parameters:
is_duplicate- indicates whether this dm is being destroyed because it is a duplicate
-
isDestroyed
boolean isDestroyed() -
getCurrentPieces
PEPiece[] getCurrentPieces() -
getCurrentPeers
PEPeer[] getCurrentPeers() -
getTrackerPeerSources
List<TrackerPeerSource> getTrackerPeerSources() -
seedPieceRecheck
boolean seedPieceRecheck()Gives the download an opportunity to schedule seeding mode piece rechecks if desired- Returns:
- true if a piece has been rechecked
-
addRateLimiter
-
getRateLimiters
-
removeRateLimiter
-
addListener
- Parameters:
listener-triggerStateChange-- Since:
- 3.1.1.1
-
addListener
-
removeListener
-
addTrackerListener
-
removeTrackerListener
-
addPeerListener
-
addPeerListener
-
removePeerListener
-
addPieceListener
-
addPieceListener
-
removePieceListener
-
addDiskListener
-
removeDiskListener
-
getActivationCount
int getActivationCount() -
addActivationListener
-
removeActivationListener
-
addTPSListener
-
informTPSChanged
void informTPSChanged() -
removeTPSListener
-
generateEvidence
-
getStorageType
-
canMoveDataFiles
boolean canMoveDataFiles()- Since:
- 3.0.5.1
-
rename
Renames the save file, torrent file and the displayed name.- Throws:
DownloadManagerException
-
renameTorrent
- Throws:
DownloadManagerException- Since:
- 3.0.5.1
-
renameTorrentSafe
Same as renameTorrent, but appends numbers if torrent already exists- Throws:
DownloadManagerException- Since:
- 4.2.0.9
-
moveTorrentFile
- Throws:
DownloadManagerException- Since:
- 3.0.5.1
-
setTorrentFile
Sets the torrent file name (will perform a move of the torrent file) - this shouldn't be used unless you know what you are doing (it requires the download to be stopped!) - it is safer to use moveTorrentFile instead.- Throws:
DownloadManagerException- Since:
- 3.0.5.3
-
canExportDownload
boolean canExportDownload()- Parameters:
event_type-- Since:
- 1.2.0.1
-
exportDownload
- Throws:
DownloadManagerException
-
fireGlobalManagerEvent
default void fireGlobalManagerEvent(int event_type) -
fireGlobalManagerEvent
-
requestAttention
void requestAttention()
-