Class DownloadImpl
- java.lang.Object
-
- com.biglybt.core.logging.LogRelation
-
- com.biglybt.pifimpl.local.download.DownloadImpl
-
- All Implemented Interfaces:
DownloadManagerActivationListener
,DownloadManagerListener
,DownloadManagerStateAttributeListener
,DownloadManagerTrackerListener
,Download
,DownloadEventNotifier
,DownloadStub
,Taggable
public class DownloadImpl extends LogRelation implements Download, DownloadManagerListener, DownloadManagerTrackerListener, DownloadManagerActivationListener, DownloadManagerStateAttributeListener
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DownloadImpl.AggregateScrapeResult
-
Nested classes/interfaces inherited from interface com.biglybt.pif.download.Download
Download.SeedingRank
-
Nested classes/interfaces inherited from interface com.biglybt.pif.download.DownloadStub
DownloadStub.DownloadStubEx, DownloadStub.DownloadStubFile
-
-
Field Summary
-
Fields inherited from interface com.biglybt.pif.download.Download
FLAG_ALLOW_PERMITTED_PEER_SOURCE_CHANGES, FLAG_DISABLE_AUTO_FILE_MOVE, FLAG_DISABLE_IP_FILTER, FLAG_DISABLE_STOP_AFTER_ALLOC, FLAG_DO_NOT_DELETE_DATA_ON_REMOVE, FLAG_ERROR_REPORTED, FLAG_FORCE_DIRECT_DELETE, FLAG_INITIAL_NETWORKS_SET, FLAG_LIGHT_WEIGHT, FLAG_LOW_NOISE, FLAG_METADATA_DOWNLOAD, FLAG_MOVE_ON_COMPLETION_DONE, FLAG_ONLY_EVER_SEEDED, FLAG_SCAN_INCOMPLETE_PIECES, FLAG_SEQUENTIAL_DOWNLOAD, ST_DOWNLOADING, ST_ERROR, ST_NAMES, ST_PREPARING, ST_QUEUED, ST_READY, ST_SEEDING, ST_STOPPED, ST_STOPPING, ST_WAITING, UD_KEY_STOP_REASON
-
Fields inherited from interface com.biglybt.core.download.DownloadManagerStateAttributeListener
WILL_BE_READ, WRITTEN
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DownloadImpl(DownloadManagerImpl _manager, DownloadManager _dm)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
activateRequest(int count)
void
addActivationListener(DownloadActivationListener l)
Adds a listener that will be invoked when a request is made to activate a torrent.void
addAttributeListener(DownloadAttributeListener listener, TorrentAttribute attr, int event_type)
Adds a listener that will be informed of when attributes on a download have been read / modified.void
addCompletionListener(DownloadCompletionListener l)
Adds a listener that will be informed when a download moves into a completed state.void
addDownloadWillBeRemovedListener(DownloadWillBeRemovedListener l)
Adds a listener that will be informed when a download is about to be removed.void
addListener(DownloadListener l)
Adds a listener that will be informed of changes to a download's state.void
addPeerListener(DownloadPeerListener listener)
Adds a listener that will be informed of when peer managers have been added / removed for a download.void
addRateLimiter(RateLimiter limiter, boolean is_upload)
void
addTrackerListener(DownloadTrackerListener l)
Adds a listener that will be informed when the latest announce/scrape results change.void
addTrackerListener(DownloadTrackerListener l, boolean immediateTrigger)
Adds a listener that will be informed when the latest announce/scrape results change.void
announceResult(TRTrackerAnnouncerResponse response)
(package private) void
announceTrackerResultsToListener(DownloadTrackerListener l)
void
attributeEventOccurred(DownloadManager download, java.lang.String attribute, int event_type)
SaveLocationChange
calculateDefaultDownloadLocation()
Returns aSaveLocationChange
object describing the appropriate location for the download (and torrent file) to exist in, based on the download's completion state, the for-completion rules in place, and theSaveLocationManager
object in use.boolean
canBeRemoved()
Tests whether or not a download can be removed.boolean
canMoveDataFiles()
Returns true if the client will allow the data files for the torrent to be moved.boolean
canStubbify()
void
changeLocation(SaveLocationChange slc)
Apply the changes in the givenSaveLocationChange
object - this includes moving torrent and data file data.void
completionChanged(DownloadManager manager, boolean bCompleted)
Notification that the completion state has changed.protected java.lang.String
convertAttribute(TorrentAttribute attribute)
protected TorrentAttribute
convertAttribute(java.lang.String name)
protected int
convertState(int dm_state)
protected void
destroy()
Download
destubbify()
void
downloadComplete(DownloadManager manager)
Notification that we were downloading and the download has completedvoid
filePriorityChanged(DownloadManager download, DiskManagerFileInfo file)
DownloadActivationEvent
getActivationState()
Gives access to the current activation state.DownloadScrapeResult
getAggregatedScrapeResult(boolean allow_caching)
java.lang.String
getAttribute(TorrentAttribute attribute)
Gets an attribute of this download.private CopyOnWriteMap
getAttributeMapForType(int event_type)
boolean
getBooleanAttribute(TorrentAttribute attribute)
Gets the value of the given attribute from the download.java.lang.String
getCategoryName()
Returns the name of the Categorylong
getCreationTime()
returns the time this download was created in millisecondsDiskManager
getDiskManager()
Return the disk manager, null if its not runningint
getDiskManagerFileCount()
Return the number of DiskManagerFile objectsDiskManagerFileInfo[]
getDiskManagerFileInfo()
Returns info about the torrent's files.DiskManagerFileInfo
getDiskManagerFileInfo(int index)
Returns file info for the given index.java.util.List<DistributedDatabase>
getDistributedDatabases()
DownloadManager
getDownload()
byte[]
getDownloadPeerId()
Get the local peerID advertised to the download swarm.int
getDownloadRateLimitBytesPerSecond()
Get the max download rate allowed for this download.java.lang.String
getErrorStateDetails()
When the download state is ERROR this method returns the error detailsboolean
getFlag(long flag)
Get the flag valuelong
getFlags()
get all the flags as a bitmapint
getIntAttribute(TorrentAttribute attribute)
Gets the value of the given attribute from the download.DownloadAnnounceResult
getLastAnnounceResult()
Gives access to the last announce result received from the tracker for the downloadDownloadScrapeResult
getLastScrapeResult()
Gives access to the last scrape result received from the tracker for the downloadjava.lang.String[]
getListAttribute(TorrentAttribute attribute)
long
getLongAttribute(TorrentAttribute attribute)
Gets the value of the given attribute from the download.java.util.Map
getMapAttribute(TorrentAttribute attribute)
int
getMaximumDownloadKBPerSecond()
Get the max download rate allowed for this downloadjava.lang.String
getName()
Returns the name of the torrent.PeerManager
getPeerManager()
return the current peer manager for the download.int
getPosition()
Returns the current position in the queue Completed and Incompleted downloads have seperate position sets.DiskManagerFileInfo
getPrimaryFile()
Returns the "Primary" file in the download.java.lang.Object[]
getQueryableInterfaces()
Query this class for a reference to another class that it may holdjava.lang.String
getRelationText()
A short description of what your class holds that can be printed by the loggerjava.lang.String
getSavePath()
This returns the full save path for the download.Download.SeedingRank
getSeedingRank()
The torrents with the highest rankings will be seeded first.int
getState()
get state from above ST_ setDownloadStats
getStats()
Gives access to the download's statisticsjava.lang.String
getStopReason()
DownloadStub.DownloadStubFile[]
getStubFiles()
int
getSubState()
For the STOPPING state this method gives the state that is being transited too (STOPPED, QUEUED or ERROR)java.util.List<Tag>
getTags()
Torrent
getTorrent()
Each download has a corresponding torrentjava.lang.String
getTorrentFileName()
Returns the full file path and name of the .torrent filebyte[]
getTorrentHash()
long
getTorrentSize()
TrackerPeerSource[]
getTrackerPeerSources()
private java.lang.String
getTrackingName(java.lang.Object obj)
int
getUploadRateLimitBytesPerSecond()
Get the max upload rate allowed for this download.java.lang.Object
getUserData(java.lang.Object key)
get user-defined key/valueboolean
hasAttribute(TorrentAttribute attribute)
Returnstrue
if the download has an explicit value stored for the given attribute.void
initialize()
See lifecycle description aboveboolean
isChecking()
When a download is completed it is rechecked (if the option is enabled).boolean
isComplete()
Indicates if the download has completed or not, exluding any files marked as Do No Downloadboolean
isComplete(boolean bIncludeDND)
Indicates if the download has completed or notboolean
isForceStart()
Retrieves whether the download is force startedboolean
isMessagingEnabled()
Is advanced AZ messaging enabled for this download.boolean
isMoving()
Returns true if the download is currently in the process of having its datafiles movedboolean
isPaused()
boolean
isPersistent()
Downloads can be persistent (be remembered across client sessions), or non-persistent.protected void
isRemovable()
boolean
isRemoved()
boolean
isStartStopLocked()
When a download is "start-stop locked" it means that seeding rules shouldn't start or stop the download as it is under manual controlboolean
isStub()
void
moveDataFiles(java.io.File new_parent_dir)
Move a download's data files to a new location.void
moveDataFiles(java.io.File new_parent_dir, java.lang.String new_name)
Move a download's data files to a new location, and rename the download at the same time.void
moveDown()
Moves the download down one positionvoid
moveTo(int pos)
Moves a download and re-orders the others appropriately.void
moveTorrentFile(java.io.File new_parent_dir)
Move a download's torrent file to a new location.void
moveUp()
Moves the download position up onevoid
pause()
Pause the downloadvoid
positionChanged(DownloadManager download, int oldPosition, int newPosition)
void
recheckData()
Performs a complete recheck of the downloaded data Download must be in stopped, queued or error state Action is performed asynchronously and will progress the download through states PREPARING back to the relevant statevoid
remove()
Removes a download.void
remove(boolean delete_torrent, boolean delete_data)
Same as "remove" but, if successful, deletes the torrent and/or datavoid
removeActivationListener(DownloadActivationListener l)
Removes a listener object added via theDownloadEventNotifier.addActivationListener(DownloadActivationListener)
method.void
removeAttributeListener(DownloadAttributeListener listener, TorrentAttribute attr, int event_type)
Removes a listener object added via themethod.
void
removeCompletionListener(DownloadCompletionListener l)
Removes a listener object removed via theDownloadEventNotifier.addCompletionListener(DownloadCompletionListener)
method.void
removeDownloadWillBeRemovedListener(DownloadWillBeRemovedListener l)
Removes a listener object added via theDownloadEventNotifier.addDownloadWillBeRemovedListener(DownloadWillBeRemovedListener)
method.void
removeListener(DownloadListener l)
Removes a listener object added via theDownloadEventNotifier.addListener(DownloadListener)
method.void
removePeerListener(DownloadPeerListener listener)
Removes a listener object added via theDownloadEventNotifier.addPeerListener(DownloadPeerListener)
method.void
removeRateLimiter(RateLimiter limiter, boolean is_upload)
void
removeTrackerListener(DownloadTrackerListener l)
Removes a listener object added via theDownloadEventNotifier.addTrackerListener(DownloadTrackerListener)
orDownloadEventNotifier.addTrackerListener(DownloadTrackerListener, boolean)
method.void
renameDownload(java.lang.String new_name)
Renames the file (for a single file torrent) or directory (for a multi file torrent) where the download is being saved to.void
requestTrackerAnnounce()
request a tracker announcevoid
requestTrackerAnnounce(boolean immediate)
request a tracker announcevoid
requestTrackerScrape(boolean immediate)
request a tracker announcevoid
restart()
See lifecycle description abovevoid
resume()
Resume the download if pausedvoid
scrapeResult(TRTrackerScraperResponse response)
void
setAnnounceResult(DownloadAnnounceResult result)
void
setAttribute(TorrentAttribute attribute, java.lang.String value)
Sets an attribute of this download.void
setBooleanAttribute(TorrentAttribute attribute, boolean value)
Sets a boolean attribute on this download.void
setCategory(java.lang.String sName)
Sets the category for the downloadvoid
setDownloadRateLimitBytesPerSecond(int max_rate_bps)
Set the max download rate allowed for this download.void
setFlag(long flag, boolean set)
Set the flag value.void
setForceStart(boolean forceStart)
Set the forcestart state of the downloadvoid
setIntAttribute(TorrentAttribute attribute, int value)
Sets an integer attribute on this download.void
setListAttribute(TorrentAttribute attribute, java.lang.String[] value)
void
setLongAttribute(TorrentAttribute attribute, long value)
Sets a long attribute on this download.void
setMapAttribute(TorrentAttribute attribute, java.util.Map value)
void
setMaximumDownloadKBPerSecond(int kb)
Sets the maximum download speed in bytes per second.void
setMessagingEnabled(boolean enabled)
Enable or disable advanced AZ messaging for this download.void
setPosition(int newPosition)
Sets the position in the queue Completed and Incompleted downloads have seperate position setsvoid
setScrapeResult(DownloadScrapeResult result)
void
setSeedingRank(Download.SeedingRank rank)
The torrents with the highest rankings will be seeded first.void
setStopReason(java.lang.String reason)
void
setUploadRateLimitBytesPerSecond(int max_rate_bps)
Set the max upload rate allowed for this download.void
setUserData(java.lang.Object key, java.lang.Object data)
set user defined value.void
start()
See lifecycle description abovevoid
startDownload(boolean force)
Simple method to start the download.void
stateChanged(DownloadManager manager, int state)
void
stop()
See lifecycle description abovevoid
stopAndQueue()
See lifecycle description abovevoid
stopAndRemove(boolean delete_torrent, boolean delete_data)
void
stopDownload()
Simple method to stop the download.DownloadStub
stubbify()
void
torrentChanged()
private void
updateAggregatedScrapeResult()
private void
updateAggregatedScrapeResult(boolean allow_caching)
-
Methods inherited from class com.biglybt.core.logging.LogRelation
propogatedRelationText, queryForClass
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.biglybt.pif.download.Download
getAggregatedScrapeResult
-
Methods inherited from interface com.biglybt.core.download.DownloadManagerListener
fileLocationChanged
-
Methods inherited from interface com.biglybt.pif.download.DownloadStub
getMainTracker
-
-
-
-
Field Detail
-
manager
private final DownloadManagerImpl manager
-
download_manager
private final DownloadManager download_manager
-
download_stats
private final DownloadStatsImpl download_stats
-
latest_state
private int latest_state
-
latest_forcedStart
private boolean latest_forcedStart
-
last_announce_result
private final DownloadAnnounceResultImpl last_announce_result
-
last_scrape_result
private final DownloadScrapeResultImpl last_scrape_result
-
aggregate_scrape
private final DownloadImpl.AggregateScrapeResult aggregate_scrape
-
torrent
private TorrentImpl torrent
-
listeners
private java.util.List listeners
-
listeners_mon
private AEMonitor listeners_mon
-
tracker_listeners
private java.util.List tracker_listeners
-
tracker_listeners_mon
private AEMonitor tracker_listeners_mon
-
removal_listeners
private java.util.List removal_listeners
-
removal_listeners_mon
private AEMonitor removal_listeners_mon
-
peer_listeners
private java.util.Map peer_listeners
-
peer_listeners_mon
private AEMonitor peer_listeners_mon
-
completion_listeners
private CopyOnWriteList completion_listeners
-
read_attribute_listeners_map_cow
private CopyOnWriteMap read_attribute_listeners_map_cow
-
write_attribute_listeners_map_cow
private CopyOnWriteMap write_attribute_listeners_map_cow
-
activation_listeners
private CopyOnWriteList activation_listeners
-
activation_state
private DownloadActivationEvent activation_state
-
announce_response_map
private java.util.Map<java.lang.String,int[]> announce_response_map
-
last_asr_calc
private volatile long last_asr_calc
-
-
Constructor Detail
-
DownloadImpl
protected DownloadImpl(DownloadManagerImpl _manager, DownloadManager _dm)
-
-
Method Detail
-
getDownload
public DownloadManager getDownload()
-
getState
public int getState()
Description copied from interface:Download
get state from above ST_ set
-
getSubState
public int getSubState()
Description copied from interface:Download
For the STOPPING state this method gives the state that is being transited too (STOPPED, QUEUED or ERROR)- Specified by:
getSubState
in interfaceDownload
- Returns:
-
convertState
protected int convertState(int dm_state)
-
getErrorStateDetails
public java.lang.String getErrorStateDetails()
Description copied from interface:Download
When the download state is ERROR this method returns the error details- Specified by:
getErrorStateDetails
in interfaceDownload
- Returns:
-
getFlags
public long getFlags()
Description copied from interface:Download
get all the flags as a bitmap
-
getFlag
public boolean getFlag(long flag)
Description copied from interface:Download
Get the flag value
-
setFlag
public void setFlag(long flag, boolean set)
Description copied from interface:Download
Set the flag value.
-
getTorrent
public Torrent getTorrent()
Description copied from interface:Download
Each download has a corresponding torrent- Specified by:
getTorrent
in interfaceDownload
- Specified by:
getTorrent
in interfaceDownloadStub
- Returns:
- the download's torrent
-
initialize
public void initialize() throws DownloadException
Description copied from interface:Download
See lifecycle description above- Specified by:
initialize
in interfaceDownload
- Throws:
DownloadException
-
start
public void start() throws DownloadException
Description copied from interface:Download
See lifecycle description above- Specified by:
start
in interfaceDownload
- Throws:
DownloadException
-
restart
public void restart() throws DownloadException
Description copied from interface:Download
See lifecycle description above- Specified by:
restart
in interfaceDownload
- Throws:
DownloadException
-
stop
public void stop() throws DownloadException
Description copied from interface:Download
See lifecycle description above- Specified by:
stop
in interfaceDownload
- Throws:
DownloadException
-
setStopReason
public void setStopReason(java.lang.String reason)
- Specified by:
setStopReason
in interfaceDownload
-
getStopReason
public java.lang.String getStopReason()
- Specified by:
getStopReason
in interfaceDownload
-
stopAndQueue
public void stopAndQueue() throws DownloadException
Description copied from interface:Download
See lifecycle description above- Specified by:
stopAndQueue
in interfaceDownload
- Throws:
DownloadException
-
recheckData
public void recheckData() throws DownloadException
Description copied from interface:Download
Performs a complete recheck of the downloaded data Download must be in stopped, queued or error state Action is performed asynchronously and will progress the download through states PREPARING back to the relevant state- Specified by:
recheckData
in interfaceDownload
- Throws:
DownloadException
-
isStartStopLocked
public boolean isStartStopLocked()
Description copied from interface:Download
When a download is "start-stop locked" it means that seeding rules shouldn't start or stop the download as it is under manual control- Specified by:
isStartStopLocked
in interfaceDownload
- Returns:
- True if download is locked and should not be started or stopped
-
isForceStart
public boolean isForceStart()
Description copied from interface:Download
Retrieves whether the download is force started- Specified by:
isForceStart
in interfaceDownload
- Returns:
- True if download is force started. False if not.
-
setForceStart
public void setForceStart(boolean forceStart)
Description copied from interface:Download
Set the forcestart state of the download- Specified by:
setForceStart
in interfaceDownload
- Parameters:
forceStart
- True - Download will start, despite any Start/Stop rules/limits
False - Turn forcestart state off. Download may or may not stop, depending on Start/Stop rules/limits
-
pause
public void pause()
Description copied from interface:Download
Pause the download
-
resume
public void resume()
Description copied from interface:Download
Resume the download if paused
-
getPosition
public int getPosition()
Description copied from interface:Download
Returns the current position in the queue Completed and Incompleted downloads have seperate position sets. This means we can have a position x for Completed, and position x for Incompleted.- Specified by:
getPosition
in interfaceDownload
-
getCreationTime
public long getCreationTime()
Description copied from interface:Download
returns the time this download was created in milliseconds- Specified by:
getCreationTime
in interfaceDownload
- Returns:
-
setPosition
public void setPosition(int newPosition)
Description copied from interface:Download
Sets the position in the queue Completed and Incompleted downloads have seperate position sets- Specified by:
setPosition
in interfaceDownload
-
moveUp
public void moveUp()
Description copied from interface:Download
Moves the download position up one
-
moveDown
public void moveDown()
Description copied from interface:Download
Moves the download down one position
-
moveTo
public void moveTo(int pos)
Description copied from interface:Download
Moves a download and re-orders the others appropriately. Note that setPosition does not do this, it merely sets the position thus making it possible, for example, for two downloads to have the same position
-
getName
public java.lang.String getName()
Description copied from interface:Download
Returns the name of the torrent. Similar to Torrent.getName() and is usefull if getTorrent() returns null and you still need the name.- Specified by:
getName
in interfaceDownload
- Specified by:
getName
in interfaceDownloadStub
- Returns:
- name of the torrent
-
getTorrentFileName
public java.lang.String getTorrentFileName()
Description copied from interface:Download
Returns the full file path and name of the .torrent file- Specified by:
getTorrentFileName
in interfaceDownload
- Returns:
- File name of the torrent.
-
getCategoryName
public java.lang.String getCategoryName()
Description copied from interface:Download
Returns the name of the Category- Specified by:
getCategoryName
in interfaceDownload
- Returns:
- name of the category
-
getAttribute
public java.lang.String getAttribute(TorrentAttribute attribute)
Description copied from interface:Download
Gets an attribute of this download. For category use the Category torrent attribute- Specified by:
getAttribute
in interfaceDownload
- Returns:
-
getListAttribute
public java.lang.String[] getListAttribute(TorrentAttribute attribute)
- Specified by:
getListAttribute
in interfaceDownload
-
setListAttribute
public void setListAttribute(TorrentAttribute attribute, java.lang.String[] value)
- Specified by:
setListAttribute
in interfaceDownload
-
setMapAttribute
public void setMapAttribute(TorrentAttribute attribute, java.util.Map value)
- Specified by:
setMapAttribute
in interfaceDownload
value
- must be bencodable - key is string, value is Map, List, Long or byte[]
-
getMapAttribute
public java.util.Map getMapAttribute(TorrentAttribute attribute)
- Specified by:
getMapAttribute
in interfaceDownload
-
setAttribute
public void setAttribute(TorrentAttribute attribute, java.lang.String value)
Description copied from interface:Download
Sets an attribute of this download. For category use the Category torrent attribute- Specified by:
setAttribute
in interfaceDownload
- Parameters:
attribute
- Previously created attributevalue
- Value to store. null to remove attribute
-
hasAttribute
public boolean hasAttribute(TorrentAttribute attribute)
Description copied from interface:Download
Returnstrue
if the download has an explicit value stored for the given attribute.- Specified by:
hasAttribute
in interfaceDownload
-
getBooleanAttribute
public boolean getBooleanAttribute(TorrentAttribute attribute)
Description copied from interface:Download
Gets the value of the given attribute from the download. If no value is set, thenfalse
will be returned.- Specified by:
getBooleanAttribute
in interfaceDownload
-
setBooleanAttribute
public void setBooleanAttribute(TorrentAttribute attribute, boolean value)
Description copied from interface:Download
Sets a boolean attribute on this download.- Specified by:
setBooleanAttribute
in interfaceDownload
-
getIntAttribute
public int getIntAttribute(TorrentAttribute attribute)
Description copied from interface:Download
Gets the value of the given attribute from the download. If no value is set, then0
will be returned.- Specified by:
getIntAttribute
in interfaceDownload
-
setIntAttribute
public void setIntAttribute(TorrentAttribute attribute, int value)
Description copied from interface:Download
Sets an integer attribute on this download.- Specified by:
setIntAttribute
in interfaceDownload
-
getLongAttribute
public long getLongAttribute(TorrentAttribute attribute)
Description copied from interface:Download
Gets the value of the given attribute from the download. If no value is set, then0
will be returned.- Specified by:
getLongAttribute
in interfaceDownload
- Specified by:
getLongAttribute
in interfaceDownloadStub
- Returns:
-
setLongAttribute
public void setLongAttribute(TorrentAttribute attribute, long value)
Description copied from interface:Download
Sets a long attribute on this download.- Specified by:
setLongAttribute
in interfaceDownload
- Specified by:
setLongAttribute
in interfaceDownloadStub
-
convertAttribute
protected java.lang.String convertAttribute(TorrentAttribute attribute)
-
convertAttribute
protected TorrentAttribute convertAttribute(java.lang.String name)
-
setCategory
public void setCategory(java.lang.String sName)
Description copied from interface:Download
Sets the category for the download- Specified by:
setCategory
in interfaceDownload
- Parameters:
sName
- Category name
-
isPersistent
public boolean isPersistent()
Description copied from interface:Download
Downloads can be persistent (be remembered across client sessions), or non-persistent.- Specified by:
isPersistent
in interfaceDownload
- Returns:
- true - persistent
false - non-persistent
-
remove
public void remove() throws DownloadException, DownloadRemovalVetoException
Description copied from interface:Download
Removes a download. The download must be stopped or in error. Removal may fail if another component does not want the removal to occur - in this case a "veto" exception is thrown- Specified by:
remove
in interfaceDownload
- Specified by:
remove
in interfaceDownloadStub
- Throws:
DownloadException
DownloadRemovalVetoException
-
remove
public void remove(boolean delete_torrent, boolean delete_data) throws DownloadException, DownloadRemovalVetoException
Description copied from interface:Download
Same as "remove" but, if successful, deletes the torrent and/or data- Specified by:
remove
in interfaceDownload
- Throws:
DownloadException
DownloadRemovalVetoException
-
stopAndRemove
public void stopAndRemove(boolean delete_torrent, boolean delete_data) throws DownloadException, DownloadRemovalVetoException
- Specified by:
stopAndRemove
in interfaceDownload
- Throws:
DownloadException
DownloadRemovalVetoException
-
canBeRemoved
public boolean canBeRemoved() throws DownloadRemovalVetoException
Description copied from interface:Download
Tests whether or not a download can be removed. Due to synchronization issues it is possible for a download to report OK here but still fail removal.- Specified by:
canBeRemoved
in interfaceDownload
- Returns:
- Throws:
DownloadRemovalVetoException
-
getStats
public DownloadStats getStats()
Description copied from interface:Download
Gives access to the download's statistics
-
isComplete
public boolean isComplete()
Description copied from interface:Download
Indicates if the download has completed or not, exluding any files marked as Do No Download- Specified by:
isComplete
in interfaceDownload
- Returns:
- Download Complete status
-
isComplete
public boolean isComplete(boolean bIncludeDND)
Description copied from interface:Download
Indicates if the download has completed or not- Specified by:
isComplete
in interfaceDownload
- Parameters:
bIncludeDND
- Whether to include DND files when determining completion state- Returns:
- Download Complete status
-
isChecking
public boolean isChecking()
Description copied from interface:Download
When a download is completed it is rechecked (if the option is enabled). This method returns true during this phase (at which time the status will be seeding)- Specified by:
isChecking
in interfaceDownload
- Returns:
-
isMoving
public boolean isMoving()
Description copied from interface:Download
Returns true if the download is currently in the process of having its datafiles moved
-
isRemovable
protected void isRemovable() throws DownloadRemovalVetoException
- Throws:
DownloadRemovalVetoException
-
destroy
protected void destroy()
-
stateChanged
public void stateChanged(DownloadManager manager, int state)
- Specified by:
stateChanged
in interfaceDownloadManagerListener
-
downloadComplete
public void downloadComplete(DownloadManager manager)
Description copied from interface:DownloadManagerListener
Notification that we were downloading and the download has completed- Specified by:
downloadComplete
in interfaceDownloadManagerListener
-
completionChanged
public void completionChanged(DownloadManager manager, boolean bCompleted)
Description copied from interface:DownloadManagerListener
Notification that the completion state has changed. Tells you when we switched from Completed to Incompleted (or visa versa) Does not get called when diskManager goes into CHECKING, but does when it goes out of CHECKING, to avoid torrents jumping momentarily from Completed to Incompleted to Completed again.- Specified by:
completionChanged
in interfaceDownloadManagerListener
-
filePriorityChanged
public void filePriorityChanged(DownloadManager download, DiskManagerFileInfo file)
- Specified by:
filePriorityChanged
in interfaceDownloadManagerListener
-
positionChanged
public void positionChanged(DownloadManager download, int oldPosition, int newPosition)
- Specified by:
positionChanged
in interfaceDownloadManagerListener
-
addListener
public void addListener(DownloadListener l)
Description copied from interface:DownloadEventNotifier
Adds a listener that will be informed of changes to a download's state.- Specified by:
addListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to add.
-
removeListener
public void removeListener(DownloadListener l)
Description copied from interface:DownloadEventNotifier
Removes a listener object added via theDownloadEventNotifier.addListener(DownloadListener)
method.- Specified by:
removeListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to remove.
-
addAttributeListener
public void addAttributeListener(DownloadAttributeListener listener, TorrentAttribute attr, int event_type)
Description copied from interface:DownloadEventNotifier
Adds a listener that will be informed of when attributes on a download have been read / modified.- Specified by:
addAttributeListener
in interfaceDownloadEventNotifier
- Parameters:
listener
- The listener to add.attr
- The torrent attribute to be notified about.event_type
- The type of event to be notified of, as defined onDownloadAttributeListener
.
-
removeAttributeListener
public void removeAttributeListener(DownloadAttributeListener listener, TorrentAttribute attr, int event_type)
Description copied from interface:DownloadEventNotifier
Removes a listener object added via themethod.
- Specified by:
removeAttributeListener
in interfaceDownloadEventNotifier
- Parameters:
listener
- The listener to remove.attr
- The torrent attribute which it registered with.event_type
- The type of event which it registered with.
-
getLastAnnounceResult
public DownloadAnnounceResult getLastAnnounceResult()
Description copied from interface:Download
Gives access to the last announce result received from the tracker for the download- Specified by:
getLastAnnounceResult
in interfaceDownload
- Returns:
-
getLastScrapeResult
public DownloadScrapeResult getLastScrapeResult()
Description copied from interface:Download
Gives access to the last scrape result received from the tracker for the download- Specified by:
getLastScrapeResult
in interfaceDownload
- Returns:
- a non-null DownloadScrapeResult
-
getAggregatedScrapeResult
public DownloadScrapeResult getAggregatedScrapeResult(boolean allow_caching)
- Specified by:
getAggregatedScrapeResult
in interfaceDownload
-
updateAggregatedScrapeResult
private void updateAggregatedScrapeResult(boolean allow_caching)
-
updateAggregatedScrapeResult
private void updateAggregatedScrapeResult()
-
scrapeResult
public void scrapeResult(TRTrackerScraperResponse response)
- Specified by:
scrapeResult
in interfaceDownloadManagerTrackerListener
-
announceTrackerResultsToListener
void announceTrackerResultsToListener(DownloadTrackerListener l)
-
announceResult
public void announceResult(TRTrackerAnnouncerResponse response)
- Specified by:
announceResult
in interfaceDownloadManagerTrackerListener
-
getTrackerPeerSources
public TrackerPeerSource[] getTrackerPeerSources()
-
getTrackingName
private java.lang.String getTrackingName(java.lang.Object obj)
-
setAnnounceResult
public void setAnnounceResult(DownloadAnnounceResult result)
- Specified by:
setAnnounceResult
in interfaceDownload
-
setScrapeResult
public void setScrapeResult(DownloadScrapeResult result)
- Specified by:
setScrapeResult
in interfaceDownload
-
torrentChanged
public void torrentChanged()
-
addTrackerListener
public void addTrackerListener(DownloadTrackerListener l)
Description copied from interface:DownloadEventNotifier
Adds a listener that will be informed when the latest announce/scrape results change.Listener events will be immediately triggered after the listener has been added.
- Specified by:
addTrackerListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to add.
-
addTrackerListener
public void addTrackerListener(DownloadTrackerListener l, boolean immediateTrigger)
Description copied from interface:DownloadEventNotifier
Adds a listener that will be informed when the latest announce/scrape results change.- Specified by:
addTrackerListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to add.immediateTrigger
- Whether to immediately trigger listener's events.
-
removeTrackerListener
public void removeTrackerListener(DownloadTrackerListener l)
Description copied from interface:DownloadEventNotifier
Removes a listener object added via theDownloadEventNotifier.addTrackerListener(DownloadTrackerListener)
orDownloadEventNotifier.addTrackerListener(DownloadTrackerListener, boolean)
method.- Specified by:
removeTrackerListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to remove.
-
addDownloadWillBeRemovedListener
public void addDownloadWillBeRemovedListener(DownloadWillBeRemovedListener l)
Description copied from interface:DownloadEventNotifier
Adds a listener that will be informed when a download is about to be removed. This gives the implementor the opportunity to veto the removal.- Specified by:
addDownloadWillBeRemovedListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to add.
-
removeDownloadWillBeRemovedListener
public void removeDownloadWillBeRemovedListener(DownloadWillBeRemovedListener l)
Description copied from interface:DownloadEventNotifier
Removes a listener object added via theDownloadEventNotifier.addDownloadWillBeRemovedListener(DownloadWillBeRemovedListener)
method.- Specified by:
removeDownloadWillBeRemovedListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to remove.
-
addPeerListener
public void addPeerListener(DownloadPeerListener listener)
Description copied from interface:DownloadEventNotifier
Adds a listener that will be informed of when peer managers have been added / removed for a download.- Specified by:
addPeerListener
in interfaceDownloadEventNotifier
- Parameters:
listener
- The listener to add.
-
removePeerListener
public void removePeerListener(DownloadPeerListener listener)
Description copied from interface:DownloadEventNotifier
Removes a listener object added via theDownloadEventNotifier.addPeerListener(DownloadPeerListener)
method.- Specified by:
removePeerListener
in interfaceDownloadEventNotifier
- Parameters:
listener
- The listener to remove.
-
activateRequest
public boolean activateRequest(int count)
- Specified by:
activateRequest
in interfaceDownloadManagerActivationListener
-
getActivationState
public DownloadActivationEvent getActivationState()
Description copied from interface:Download
Gives access to the current activation state. Note that we currently only fire the activation listener on an increase in activation requirements. This method however gives the current view of the state and takes into account decreases too- Specified by:
getActivationState
in interfaceDownload
- Returns:
-
addActivationListener
public void addActivationListener(DownloadActivationListener l)
Description copied from interface:DownloadEventNotifier
Adds a listener that will be invoked when a request is made to activate a torrent.- Specified by:
addActivationListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to add.
-
removeActivationListener
public void removeActivationListener(DownloadActivationListener l)
Description copied from interface:DownloadEventNotifier
Removes a listener object added via theDownloadEventNotifier.addActivationListener(DownloadActivationListener)
method.- Specified by:
removeActivationListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to remove.
-
addCompletionListener
public void addCompletionListener(DownloadCompletionListener l)
Description copied from interface:DownloadEventNotifier
Adds a listener that will be informed when a download moves into a completed state.- Specified by:
addCompletionListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to add.
-
removeCompletionListener
public void removeCompletionListener(DownloadCompletionListener l)
Description copied from interface:DownloadEventNotifier
Removes a listener object removed via theDownloadEventNotifier.addCompletionListener(DownloadCompletionListener)
method.- Specified by:
removeCompletionListener
in interfaceDownloadEventNotifier
- Parameters:
l
- The listener to remove.
-
getPeerManager
public PeerManager getPeerManager()
Description copied from interface:Download
return the current peer manager for the download.- Specified by:
getPeerManager
in interfaceDownload
- Returns:
- null returned if torrent currently doesn't have one (e.g. it is stopped)
-
getDiskManager
public DiskManager getDiskManager()
Description copied from interface:Download
Return the disk manager, null if its not running- Specified by:
getDiskManager
in interfaceDownload
- Returns:
-
getDiskManagerFileCount
public int getDiskManagerFileCount()
Description copied from interface:Download
Return the number of DiskManagerFile objects- Specified by:
getDiskManagerFileCount
in interfaceDownload
- Returns:
-
getDiskManagerFileInfo
public DiskManagerFileInfo getDiskManagerFileInfo(int index)
Description copied from interface:Download
Returns file info for the given index. Note that this will return "stub" values if the download isn't running (not including info such as completion status)- Specified by:
getDiskManagerFileInfo
in interfaceDownload
- Returns:
- null if index is invalid
-
getPrimaryFile
public DiskManagerFileInfo getPrimaryFile()
Description copied from interface:Download
Returns the "Primary" file in the download. Usually the largest one- Specified by:
getPrimaryFile
in interfaceDownload
-
getDiskManagerFileInfo
public DiskManagerFileInfo[] getDiskManagerFileInfo()
Description copied from interface:Download
Returns info about the torrent's files. Note that this will return "stub" values if the download isn't running (not including info such as completion status)- Specified by:
getDiskManagerFileInfo
in interfaceDownload
- Returns:
-
setMaximumDownloadKBPerSecond
public void setMaximumDownloadKBPerSecond(int kb)
Description copied from interface:Download
Sets the maximum download speed in bytes per second. 0 -> unlimited- Specified by:
setMaximumDownloadKBPerSecond
in interfaceDownload
-
getMaximumDownloadKBPerSecond
public int getMaximumDownloadKBPerSecond()
Description copied from interface:Download
Get the max download rate allowed for this download- Specified by:
getMaximumDownloadKBPerSecond
in interfaceDownload
- Returns:
- upload rate in KB/s, 0 for unlimited
Since 4.8.1.3: -1 for download disabled
-
getUploadRateLimitBytesPerSecond
public int getUploadRateLimitBytesPerSecond()
Description copied from interface:Download
Get the max upload rate allowed for this download.- Specified by:
getUploadRateLimitBytesPerSecond
in interfaceDownload
- Returns:
- upload rate in bytes per second, 0 for unlimited, -1 for upload disabled
-
setUploadRateLimitBytesPerSecond
public void setUploadRateLimitBytesPerSecond(int max_rate_bps)
Description copied from interface:Download
Set the max upload rate allowed for this download.- Specified by:
setUploadRateLimitBytesPerSecond
in interfaceDownload
- Parameters:
max_rate_bps
- limit in bytes per second, 0 for unlimited, -1 for upload disabled
-
getDownloadRateLimitBytesPerSecond
public int getDownloadRateLimitBytesPerSecond()
Description copied from interface:Download
Get the max download rate allowed for this download.- Specified by:
getDownloadRateLimitBytesPerSecond
in interfaceDownload
- Returns:
- upload rate in bytes per second, 0 for unlimited, -1 for download disabled
-
setDownloadRateLimitBytesPerSecond
public void setDownloadRateLimitBytesPerSecond(int max_rate_bps)
Description copied from interface:Download
Set the max download rate allowed for this download.- Specified by:
setDownloadRateLimitBytesPerSecond
in interfaceDownload
- Parameters:
max_rate_bps
- limit in bytes per second, 0 for unlimited, -1 for dowmload disabled
-
addRateLimiter
public void addRateLimiter(RateLimiter limiter, boolean is_upload)
- Specified by:
addRateLimiter
in interfaceDownload
- Parameters:
limiter
- create via ConnectionManageris_upload
- false -> download limit
-
removeRateLimiter
public void removeRateLimiter(RateLimiter limiter, boolean is_upload)
- Specified by:
removeRateLimiter
in interfaceDownload
-
getSeedingRank
public Download.SeedingRank getSeedingRank()
Description copied from interface:Download
The torrents with the highest rankings will be seeded first.- Specified by:
getSeedingRank
in interfaceDownload
- Returns:
- Seeding Rank
-
setSeedingRank
public void setSeedingRank(Download.SeedingRank rank)
Description copied from interface:Download
The torrents with the highest rankings will be seeded first.- Specified by:
setSeedingRank
in interfaceDownload
- Parameters:
rank
- New Ranking
-
getSavePath
public java.lang.String getSavePath()
Description copied from interface:Download
This returns the full save path for the download. If the download is a simple torrent, this will be the full path of the file being downloaded. If the download is a multiple file torrent, this will be the path to the directory containing all the files in the torrent.- Specified by:
getSavePath
in interfaceDownload
- Specified by:
getSavePath
in interfaceDownloadStub
- Returns:
- Full save path for this download.
-
moveDataFiles
public void moveDataFiles(java.io.File new_parent_dir) throws DownloadException
Description copied from interface:Download
Move a download's data files to a new location. If a download is running, it will be automatically paused and resumed afterwards - be aware that this behaviour may generate stateChanged events being fired.- Specified by:
moveDataFiles
in interfaceDownload
- Parameters:
new_parent_dir
- New location. Note that non-simple torrents' data will be placed in a subdirectory of the torrent's name (Download.getName()
) under this new_parent_dir- Throws:
DownloadException
-
moveDataFiles
public void moveDataFiles(java.io.File new_parent_dir, java.lang.String new_name) throws DownloadException
Description copied from interface:Download
Move a download's data files to a new location, and rename the download at the same time. Download must be stopped and persistent. This is equivalent to calling moveDataFiles[File] and then renameDownload[String]. For convenience, either argument can be null, but not both.If a download is running, it will be automatically paused and resumed afterwards - be aware that this behaviour may generate stateChanged events being fired.
- Specified by:
moveDataFiles
in interfaceDownload
- 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 ofDownload.getName()
.- Throws:
DownloadException
-
renameDownload
public void renameDownload(java.lang.String new_name) throws DownloadException
Description copied from interface:Download
Renames the file (for a single file torrent) or directory (for a multi file torrent) where the download is being saved to. The download must be in a state to move the data files to a new location (seeDownload.moveDataFiles(File)
).This will not rename the displayed name for the torrent - if you wish to do that, you must do it via the
TorrentAttribute
class.If a download is running, it will be automatically paused and resumed afterwards - be aware that this behaviour may generate stateChanged events being fired.
- Specified by:
renameDownload
in interfaceDownload
- Parameters:
new_name
- New name for the download.- Throws:
DownloadException
- See Also:
Download.moveDataFiles(File)
-
moveTorrentFile
public void moveTorrentFile(java.io.File new_parent_dir) throws DownloadException
Description copied from interface:Download
Move a download's torrent file to a new location. Download must be stopped and persistent- Specified by:
moveTorrentFile
in interfaceDownload
- Throws:
DownloadException
-
requestTrackerAnnounce
public void requestTrackerAnnounce()
Description copied from interface:Download
request a tracker announce- Specified by:
requestTrackerAnnounce
in interfaceDownload
-
requestTrackerAnnounce
public void requestTrackerAnnounce(boolean immediate)
Description copied from interface:Download
request a tracker announce- Specified by:
requestTrackerAnnounce
in interfaceDownload
-
requestTrackerScrape
public void requestTrackerScrape(boolean immediate)
Description copied from interface:Download
request a tracker announce- Specified by:
requestTrackerScrape
in interfaceDownload
-
getDownloadPeerId
public byte[] getDownloadPeerId()
Description copied from interface:Download
Get the local peerID advertised to the download swarm.- Specified by:
getDownloadPeerId
in interfaceDownload
- Returns:
- self peer id
-
isMessagingEnabled
public boolean isMessagingEnabled()
Description copied from interface:Download
Is advanced AZ messaging enabled for this download.- Specified by:
isMessagingEnabled
in interfaceDownload
- Returns:
- true if enabled, false if disabled
-
setMessagingEnabled
public void setMessagingEnabled(boolean enabled)
Description copied from interface:Download
Enable or disable advanced AZ messaging for this download.- Specified by:
setMessagingEnabled
in interfaceDownload
- Parameters:
enabled
- true to enabled, false to disabled
-
getRelationText
public java.lang.String getRelationText()
Description copied from class:LogRelation
A short description of what your class holds that can be printed by the logger- Overrides:
getRelationText
in classLogRelation
- Returns:
-
getQueryableInterfaces
public java.lang.Object[] getQueryableInterfaces()
Description copied from class:LogRelation
Query this class for a reference to another class that it may hold- Overrides:
getQueryableInterfaces
in classLogRelation
- Returns:
- If found, the class desired. Otherwise, null.
-
getAttributeMapForType
private CopyOnWriteMap getAttributeMapForType(int event_type)
-
canMoveDataFiles
public boolean canMoveDataFiles()
Description copied from interface:Download
Returns true if the client will allow the data files for the torrent to be moved.- Specified by:
canMoveDataFiles
in interfaceDownload
-
attributeEventOccurred
public void attributeEventOccurred(DownloadManager download, java.lang.String attribute, int event_type)
- Specified by:
attributeEventOccurred
in interfaceDownloadManagerStateAttributeListener
-
calculateDefaultDownloadLocation
public SaveLocationChange calculateDefaultDownloadLocation()
Description copied from interface:Download
Returns aSaveLocationChange
object describing the appropriate location for the download (and torrent file) to exist in, based on the download's completion state, the for-completion rules in place, and theSaveLocationManager
object in use.- Specified by:
calculateDefaultDownloadLocation
in interfaceDownload
-
getUserData
public java.lang.Object getUserData(java.lang.Object key)
Description copied from interface:Download
get user-defined key/value- Specified by:
getUserData
in interfaceDownload
- Returns:
-
setUserData
public void setUserData(java.lang.Object key, java.lang.Object data)
Description copied from interface:Download
set user defined value. this is TRANSIENT and not persisted over the client stop/start- Specified by:
setUserData
in interfaceDownload
-
startDownload
public void startDownload(boolean force)
Description copied from interface:Download
Simple method to start the download. Will not raise an error if it didn't work, or if the download is already running.- Specified by:
startDownload
in interfaceDownload
- Parameters:
force
- true to force the download to be started.
-
stopDownload
public void stopDownload()
Description copied from interface:Download
Simple method to stop the download. Will not raise an error if it didn't work, or if the download is already stopped.- Specified by:
stopDownload
in interfaceDownload
-
isStub
public boolean isStub()
- Specified by:
isStub
in interfaceDownloadStub
-
canStubbify
public boolean canStubbify()
- Specified by:
canStubbify
in interfaceDownload
-
stubbify
public DownloadStub stubbify() throws DownloadException, DownloadRemovalVetoException
- Specified by:
stubbify
in interfaceDownload
- Throws:
DownloadException
DownloadRemovalVetoException
-
destubbify
public Download destubbify() throws DownloadException
- Specified by:
destubbify
in interfaceDownloadStub
- Throws:
DownloadException
-
getDistributedDatabases
public java.util.List<DistributedDatabase> getDistributedDatabases()
- Specified by:
getDistributedDatabases
in interfaceDownload
- Returns:
-
getTorrentHash
public byte[] getTorrentHash()
- Specified by:
getTorrentHash
in interfaceDownloadStub
-
getTorrentSize
public long getTorrentSize()
- Specified by:
getTorrentSize
in interfaceDownloadStub
-
getStubFiles
public DownloadStub.DownloadStubFile[] getStubFiles()
- Specified by:
getStubFiles
in interfaceDownloadStub
-
changeLocation
public void changeLocation(SaveLocationChange slc) throws DownloadException
Description copied from interface:Download
Apply the changes in the givenSaveLocationChange
object - this includes moving torrent and data file data.- Specified by:
changeLocation
in interfaceDownload
- Parameters:
slc
- The change to apply.- Throws:
DownloadException
- If there is a problem moving the data.
-
-