1 /* 2 * Created on 15-Nov-2004 3 * Created by Paul Gardner 4 * Copyright (C) Azureus Software, Inc, All Rights Reserved. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 */ 19 20 package org.gudy.azureus2.core3.download; 21 22 import java.io.File; 23 import java.util.List; 24 import java.util.Map; 25 26 import org.gudy.azureus2.core3.category.Category; 27 import org.gudy.azureus2.core3.disk.DiskManagerFileInfo; 28 import org.gudy.azureus2.core3.torrent.TOTorrent; 29 import org.gudy.azureus2.core3.util.IndentWriter; 30 import org.gudy.azureus2.plugins.download.Download; 31 32 import com.aelitis.azureus.core.util.LinkFileMap; 33 34 /** 35 * @author parg 36 */ 37 38 public interface 39 DownloadManagerState 40 { 41 public static final String AT_VERSION = "version"; 42 public static final String AT_CATEGORY = "category"; 43 public static final String AT_NETWORKS = "networks"; 44 public static final String AT_USER = "user"; 45 public static final String AT_PEER_SOURCES = "peersources"; 46 public static final String AT_PEER_SOURCES_DENIED = "peersourcesdenied"; 47 public static final String AT_TRACKER_CLIENT_EXTENSIONS = "trackerclientextensions"; 48 public static final String AT_FILE_LINKS_DEPRECATED = "filelinks"; 49 public static final String AT_FILE_LINKS2 = "filelinks2"; 50 public static final String AT_FILE_STORE_TYPES = "storetypes"; 51 public static final String AT_FILE_DOWNLOADED = "filedownloaded"; 52 public static final String AT_FLAGS = "flags"; 53 public static final String AT_PARAMETERS = "parameters"; 54 public static final String AT_DISPLAY_NAME = "displayname"; 55 public static final String AT_USER_COMMENT = "comment"; 56 public static final String AT_RELATIVE_SAVE_PATH = "relativepath"; 57 public static final String AT_SECRETS = "secrets"; 58 public static final String AT_RESUME_STATE = "resumecomplete"; 59 public static final String AT_PRIMARY_FILE = "primaryfile"; 60 public static final String AT_PRIMARY_FILE_IDX = "primaryfileidx"; 61 public static final String AT_TIME_SINCE_DOWNLOAD = "timesincedl"; 62 public static final String AT_TIME_SINCE_UPLOAD = "timesinceul"; 63 public static final String AT_AVAIL_BAD_TIME = "badavail"; 64 public static final String AT_TIME_STOPPED = "timestopped"; 65 public static final String AT_INCOMP_FILE_SUFFIX = "incompfilesuffix"; 66 public static final String AT_SCRAPE_CACHE = "scrapecache"; // long value, seeds in upper word, leechers in lower 67 public static final String AT_SCRAPE_CACHE_SOURCE = "scsrc"; // int value - 0=tracker; 1=subscription etc 68 public static final String AT_REORDER_MIN_MB = "reordermb"; 69 public static final String AT_MD_INFO_DICT_SIZE = "mdinfodictsize"; 70 public static final String AT_FILE_OTHER_HASHES = "fileotherhashes"; 71 public static final String AT_CANONICAL_SD_DMAP = "canosavedir"; 72 public static final String AT_DND_SUBFOLDER = "dnd_sf"; 73 public static final String AT_PEAK_RECEIVE_RATE = "pkdo"; 74 public static final String AT_PEAK_SEND_RATE = "pkup"; 75 public static final String AT_DL_FILE_ALERTS = "df_alerts"; 76 public static final String AT_SHARE_RATIO_PROGRESS = "sr.prog"; // long: left word - timestamp in secs, right word sr in 1000ths 77 public static final String AT_FILES_EXPANDED = "file.expand"; // boolean 78 public static final String AT_MERGED_DATA = "mergedata"; // long 79 public static final String AT_DND_PREFIX = "dnd_pfx"; // string 80 public static final String AT_AGGREGATE_SCRAPE_CACHE = "agsc"; // string <update_time_mins>,<seeds>,<leechers> 81 public static final String AT_COMPLETE_LAST_TIME = "complt"; // long - last time download reported complete, -1 if reported incomplete, 0 if unknown 82 public static final String AT_LAST_ADDED_TO_ACTIVE_TAG = "last.act.tag"; // long - last time added to active tag 83 84 public static Object[][] ATTRIBUTE_DEFAULTS = { 85 { AT_VERSION, new Integer( -1 )}, 86 { AT_TIME_SINCE_DOWNLOAD, new Integer( -1 )}, 87 { AT_TIME_SINCE_UPLOAD, new Integer( -1 )}, 88 { AT_AVAIL_BAD_TIME, new Long( -1 )}, 89 { AT_SCRAPE_CACHE, new Long( -1 )}, 90 { AT_SCRAPE_CACHE_SOURCE, new Integer( 0 )}, 91 { AT_REORDER_MIN_MB, new Integer( -1 )}, 92 { AT_SHARE_RATIO_PROGRESS, new Long( 0 )}, 93 }; 94 95 public static final long FLAG_ONLY_EVER_SEEDED = Download.FLAG_ONLY_EVER_SEEDED; 96 public static final long FLAG_SCAN_INCOMPLETE_PIECES = Download.FLAG_SCAN_INCOMPLETE_PIECES; 97 public static final long FLAG_DISABLE_AUTO_FILE_MOVE = Download.FLAG_DISABLE_AUTO_FILE_MOVE; 98 public static final long FLAG_MOVE_ON_COMPLETION_DONE = Download.FLAG_MOVE_ON_COMPLETION_DONE; 99 public static final long FLAG_LOW_NOISE = Download.FLAG_LOW_NOISE; 100 public static final long FLAG_ALLOW_PERMITTED_PEER_SOURCE_CHANGES = Download.FLAG_ALLOW_PERMITTED_PEER_SOURCE_CHANGES; 101 public static final long FLAG_DO_NOT_DELETE_DATA_ON_REMOVE = Download.FLAG_DO_NOT_DELETE_DATA_ON_REMOVE; 102 public static final long FLAG_FORCE_DIRECT_DELETE = Download.FLAG_FORCE_DIRECT_DELETE; 103 public static final long FLAG_DISABLE_IP_FILTER = Download.FLAG_DISABLE_IP_FILTER; 104 public static final long FLAG_METADATA_DOWNLOAD = Download.FLAG_METADATA_DOWNLOAD; 105 public static final long FLAG_ERROR_REPORTED = Download.FLAG_ERROR_REPORTED; 106 public static final long FLAG_INITIAL_NETWORKS_SET = Download.FLAG_INITIAL_NETWORKS_SET; 107 108 public static final String PARAM_MAX_PEERS = "max.peers"; 109 public static final String PARAM_MAX_PEERS_WHEN_SEEDING = "max.peers.when.seeding"; 110 public static final String PARAM_MAX_PEERS_WHEN_SEEDING_ENABLED = "max.peers.when.seeding.enabled"; 111 public static final String PARAM_MAX_SEEDS = "max.seeds"; 112 public static final String PARAM_MAX_UPLOADS = "max.uploads"; 113 public static final String PARAM_MAX_UPLOADS_WHEN_SEEDING = "max.uploads.when.seeding"; 114 public static final String PARAM_MAX_UPLOADS_WHEN_SEEDING_ENABLED = "max.uploads.when.seeding.enabled"; 115 public static final String PARAM_STATS_COUNTED = "stats.counted"; 116 public static final String PARAM_DOWNLOAD_ADDED_TIME = "stats.download.added.time"; 117 public static final String PARAM_DOWNLOAD_COMPLETED_TIME = "stats.download.completed.time"; 118 public static final String PARAM_DOWNLOAD_FILE_COMPLETED_TIME = "stats.download.file.completed.time"; 119 public static final String PARAM_DOWNLOAD_LAST_ACTIVE_TIME = "stats.download.last.active.time"; 120 public static final String PARAM_MAX_UPLOAD_WHEN_BUSY = "max.upload.when.busy"; 121 public static final String PARAM_DND_FLAGS = "dndflags"; 122 public static final String PARAM_RANDOM_SEED = "rand"; 123 public static final String PARAM_UPLOAD_PRIORITY = "up.pri"; 124 public static final String PARAM_MIN_SHARE_RATIO = "sr.min"; // in thousandths - 1000 = sr of 1.0 125 public static final String PARAM_MAX_SHARE_RATIO = "sr.max"; // in thousandths - 1000 = sr of 1.0 126 127 public static final int DEFAULT_MAX_UPLOADS = 4; 128 public static final int MIN_MAX_UPLOADS = 2; 129 public static final int DEFAULT_UPLOAD_PRIORITY = 0; 130 131 public static Object[][] PARAMETERS = { 132 { PARAM_MAX_PEERS, new Integer( 0 ) }, 133 { PARAM_MAX_PEERS_WHEN_SEEDING, new Integer( 0 ) }, 134 { PARAM_MAX_PEERS_WHEN_SEEDING_ENABLED, new Boolean( false ) }, 135 { PARAM_MAX_SEEDS, new Integer( 0 ) }, 136 { PARAM_MAX_UPLOADS, new Long( DEFAULT_MAX_UPLOADS ) }, 137 { PARAM_MAX_UPLOADS_WHEN_SEEDING, new Integer( DEFAULT_MAX_UPLOADS ) }, 138 { PARAM_MAX_UPLOADS_WHEN_SEEDING_ENABLED, new Boolean( false ) }, 139 { PARAM_STATS_COUNTED, new Boolean( false ) }, 140 { PARAM_DOWNLOAD_ADDED_TIME, new Long( 0 ) }, 141 { PARAM_DOWNLOAD_FILE_COMPLETED_TIME, new Long( 0 ) }, 142 { PARAM_DOWNLOAD_COMPLETED_TIME, new Long( 0 ) }, 143 { PARAM_DOWNLOAD_LAST_ACTIVE_TIME, new Long( 0 ) }, 144 { PARAM_MAX_UPLOAD_WHEN_BUSY, new Long( 0 ) }, 145 { PARAM_DND_FLAGS, new Long( 0 ) }, 146 { PARAM_RANDOM_SEED, new Long( 0 ) }, 147 { PARAM_UPLOAD_PRIORITY, new Integer( DEFAULT_UPLOAD_PRIORITY ) }, 148 { PARAM_MIN_SHARE_RATIO, new Integer( 0 ) }, 149 { PARAM_MAX_SHARE_RATIO, new Integer( 0 ) }, 150 }; 151 152 public TOTorrent getTorrent()153 getTorrent(); 154 155 public DownloadManager getDownloadManager()156 getDownloadManager(); 157 158 public File getStateFile( )159 getStateFile( ); 160 161 public void setFlag( long flag, boolean set )162 setFlag( 163 long flag, 164 boolean set ); 165 166 public boolean getFlag( long flag )167 getFlag( 168 long flag ); 169 170 public long getFlags()171 getFlags(); 172 173 /** 174 * Reset to default value 175 * @param name 176 */ 177 178 public void setParameterDefault( String name )179 setParameterDefault( 180 String name ); 181 182 public int getIntParameter( String name )183 getIntParameter( 184 String name ); 185 186 public void setIntParameter( String name, int value )187 setIntParameter( 188 String name, 189 int value ); 190 191 public long getLongParameter( String name )192 getLongParameter( 193 String name ); 194 195 public void setLongParameter( String name, long value )196 setLongParameter( 197 String name, 198 long value ); 199 200 public boolean getBooleanParameter( String name )201 getBooleanParameter( 202 String name ); 203 204 public void setBooleanParameter( String name, boolean value )205 setBooleanParameter( 206 String name, 207 boolean value ); 208 209 public void clearResumeData()210 clearResumeData(); 211 212 public Map getResumeData()213 getResumeData(); 214 215 public void setResumeData( Map data )216 setResumeData( 217 Map data ); 218 219 public boolean isResumeDataComplete()220 isResumeDataComplete(); 221 222 public void clearTrackerResponseCache()223 clearTrackerResponseCache(); 224 225 public Map getTrackerResponseCache()226 getTrackerResponseCache(); 227 228 public void setTrackerResponseCache( Map value )229 setTrackerResponseCache( 230 Map value ); 231 232 public Category getCategory()233 getCategory(); 234 235 public void setCategory( Category cat )236 setCategory( 237 Category cat ); 238 getDisplayName()239 public String getDisplayName(); setDisplayName(String name)240 public void setDisplayName(String name); 241 getUserComment()242 public String getUserComment(); setUserComment(String name)243 public void setUserComment(String name); 244 getRelativeSavePath()245 public String getRelativeSavePath(); 246 setPrimaryFile(DiskManagerFileInfo dmfi)247 public void setPrimaryFile(DiskManagerFileInfo dmfi); getPrimaryFile()248 public DiskManagerFileInfo getPrimaryFile(); 249 250 public String getTrackerClientExtensions()251 getTrackerClientExtensions(); 252 253 public void setTrackerClientExtensions( String value )254 setTrackerClientExtensions( 255 String value ); 256 257 public String[] // from AENetworkClassifier constants getNetworks()258 getNetworks(); 259 260 public boolean isNetworkEnabled( String network)261 isNetworkEnabled( 262 String network); //from AENetworkClassifier constants 263 264 public void setNetworks( String[] networks )265 setNetworks( 266 String[] networks ); // from AENetworkClassifier constants 267 268 public void setNetworkEnabled( String network, boolean enabled)269 setNetworkEnabled( 270 String network, // from AENetworkClassifier constants 271 boolean enabled); 272 273 public String[] // from PEPeerSource constants getPeerSources()274 getPeerSources(); 275 276 public boolean isPeerSourcePermitted( String peerSource )277 isPeerSourcePermitted( 278 String peerSource ); 279 280 public void setPeerSourcePermitted( String peerSource, boolean permitted )281 setPeerSourcePermitted( 282 String peerSource, 283 boolean permitted ); 284 285 public boolean isPeerSourceEnabled( String peerSource)286 isPeerSourceEnabled( 287 String peerSource); // from PEPeerSource constants 288 289 public void setPeerSources( String[] sources )290 setPeerSources( 291 String[] sources ); // from PEPeerSource constants 292 293 public void setPeerSourceEnabled( String source, boolean enabled)294 setPeerSourceEnabled( 295 String source, // from PEPeerSource constants 296 boolean enabled); 297 298 // file links 299 300 public void setFileLink( int source_index, File link_source, File link_destination )301 setFileLink( 302 int source_index, 303 File link_source, 304 File link_destination ); 305 306 public void setFileLinks( List<Integer> source_indexes, List<File> link_sources, List<File> link_destinations )307 setFileLinks( 308 List<Integer> source_indexes, 309 List<File> link_sources, 310 List<File> link_destinations ); 311 312 public void clearFileLinks()313 clearFileLinks(); 314 315 public File getFileLink( int source_index, File link_source )316 getFileLink( 317 int source_index, 318 File link_source ); 319 320 /** 321 * returns a File -> File map of the defined links (empty if no links) 322 * @return 323 */ 324 325 public LinkFileMap getFileLinks()326 getFileLinks(); 327 328 /** 329 * @return 330 */ isOurContent()331 boolean isOurContent(); 332 333 // General access - make sure you use an AT_ value defined above when calling 334 // these methods. setAttribute(String name, String value)335 public void setAttribute(String name, String value); getAttribute(String name)336 public String getAttribute(String name); setMapAttribute(String name, Map value)337 public void setMapAttribute(String name, Map value); getMapAttribute(String name)338 public Map getMapAttribute(String name); setListAttribute(String name, String[] values)339 public void setListAttribute(String name, String[] values); getListAttribute(String name)340 public String[] getListAttribute(String name); getListAttribute(String name, int idx)341 public String getListAttribute(String name, int idx); setIntAttribute(String name, int value)342 public void setIntAttribute(String name, int value); getIntAttribute(String name)343 public int getIntAttribute(String name); setLongAttribute(String name, long value)344 public void setLongAttribute(String name, long value); getLongAttribute(String name)345 public long getLongAttribute(String name); setBooleanAttribute(String name, boolean value)346 public void setBooleanAttribute(String name, boolean value); getBooleanAttribute(String name)347 public boolean getBooleanAttribute(String name); hasAttribute(String name)348 public boolean hasAttribute(String name); 349 350 public void setActive( boolean active )351 setActive( 352 boolean active ); 353 discardFluff()354 public void discardFluff(); 355 356 public void save()357 save(); 358 359 public boolean exportState( File target_dir )360 exportState( 361 File target_dir ); 362 363 /** 364 * deletes the saved state 365 */ 366 367 public void delete()368 delete(); 369 370 public void addListener( DownloadManagerStateListener l )371 addListener( 372 DownloadManagerStateListener l ); 373 374 public void removeListener( DownloadManagerStateListener l )375 removeListener( 376 DownloadManagerStateListener l ); 377 378 /** 379 * @param name 380 * @return 381 */ parameterExists(String name)382 boolean parameterExists(String name); 383 generateEvidence(IndentWriter writer)384 public void generateEvidence(IndentWriter writer); 385 dump( IndentWriter writer )386 public void dump( IndentWriter writer ); 387 388 /** 389 * This method should only be invoked in matching try-finally pairs. If it is invoked with true 390 * multiple times it must be invoked with false the equal amount of times to reallow state 391 * writes 392 * 393 * @param suppress 394 * when set to true prevents flushing of the state/increments the internal nesting 395 * counter, decrements/allows flush otherwise 396 */ suppressStateSave(boolean suppress)397 public void suppressStateSave(boolean suppress); 398 addListener(DownloadManagerStateAttributeListener l, String attribute, int event_type)399 public void addListener(DownloadManagerStateAttributeListener l, String attribute, int event_type); removeListener(DownloadManagerStateAttributeListener l, String attribute, int event_type)400 public void removeListener(DownloadManagerStateAttributeListener l, String attribute, int event_type); 401 } 402