FileDocCategorySizeDatePackage
DownloadImpl.javaAPI DocAzureus 3.0.3.436286Tue Sep 04 07:56:44 BST 2007org.gudy.azureus2.pluginsimpl.local.download

DownloadImpl

public class DownloadImpl extends org.gudy.azureus2.core3.logging.LogRelation implements DownloadManagerListener, DownloadManagerTrackerListener, DownloadManagerPeerListener, DownloadManagerStateListener, DownloadManagerActivationListener, org.gudy.azureus2.plugins.download.Download
author
parg

Fields Summary
private DownloadManager
download_manager
private DownloadStatsImpl
download_stats
private int
latest_state
private boolean
latest_forcedStart
private DownloadAnnounceResultImpl
last_announce_result
private DownloadScrapeResultImpl
last_scrape_result
private org.gudy.azureus2.pluginsimpl.local.torrent.TorrentImpl
torrent
private List
listeners
private AEMonitor
listeners_mon
private List
property_listeners
private List
tracker_listeners
private AEMonitor
tracker_listeners_mon
private List
removal_listeners
private AEMonitor
removal_listeners_mon
private List
peer_listeners
private AEMonitor
peer_listeners_mon
private com.aelitis.azureus.core.util.CopyOnWriteList
activation_listeners
private org.gudy.azureus2.plugins.download.DownloadActivationEvent
activation_state
Constructors Summary
protected DownloadImpl(DownloadManager _dm)

	
	
	
				 
	
		download_manager	= _dm;
		download_stats		= new DownloadStatsImpl( download_manager );
		
		activation_state = 
			new DownloadActivationEvent()
			{
				public Download
				getDownload()
				{
					return( DownloadImpl.this );
				}
				
				public int
				getActivationCount()
				{
					return( download_manager.getActivationCount());
				}
			};
			
		download_manager.addListener( this );
		
		latest_forcedStart = download_manager.isForceStart();
	
Methods Summary
public booleanactivateRequest(int count)

		DownloadActivationEvent event = 
			new DownloadActivationEvent()
		{
			public Download 
			getDownload() 
			{
				return( DownloadImpl.this );
			}
			
			public int
			getActivationCount()
			{
				return( count );
			}
		};
		
		for (Iterator it=activation_listeners.iterator();it.hasNext();){	
				
			try{
				DownloadActivationListener	listener = (DownloadActivationListener)it.next();
				
				if ( listener.activationRequested( event )){
					
					return( true );
				}
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
		
		return( false );
	
public voidaddActivationListener(org.gudy.azureus2.plugins.download.DownloadActivationListener l)

		try{
			peer_listeners_mon.enter();
		
			activation_listeners.add( l );
			
			if ( activation_listeners.size() == 1 ){
				
				download_manager.addActivationListener( this );
			}
		}finally{
			
			peer_listeners_mon.exit();
		}
	
public voidaddDownloadWillBeRemovedListener(org.gudy.azureus2.plugins.download.DownloadWillBeRemovedListener l)

		try{
			removal_listeners_mon.enter();
			
			List	new_removal_listeners	= new ArrayList( removal_listeners );
			
			new_removal_listeners.add(l);
			
			removal_listeners	= new_removal_listeners;
			
		}finally{
			
			removal_listeners_mon.exit();
		}
	
public voidaddListener(org.gudy.azureus2.plugins.download.DownloadListener l)

		try{
			listeners_mon.enter();
			
			List	new_listeners = new ArrayList( listeners );
			
			new_listeners.add(l);
			
			listeners	= new_listeners;
		}finally{
			
			listeners_mon.exit();
		}
	
public voidaddPeerListener(org.gudy.azureus2.plugins.download.DownloadPeerListener l)

		try{
			peer_listeners_mon.enter();
		
			List	new_peer_listeners	= new ArrayList( peer_listeners );
			
			new_peer_listeners.add( l );
			
			peer_listeners	= new_peer_listeners;
			
			if ( peer_listeners.size() == 1 ){
				
				download_manager.addPeerListener( this );
			}
		}finally{
			
			peer_listeners_mon.exit();
		}
	
public voidaddPropertyListener(org.gudy.azureus2.plugins.download.DownloadPropertyListener l)

		try{
			tracker_listeners_mon.enter();
	
			List	new_property_listeners = new ArrayList( property_listeners );
			
			new_property_listeners.add( l );
			
			property_listeners	= new_property_listeners;
			
			if ( property_listeners.size() == 1 ){
				
				download_manager.getDownloadState().addListener( this );
			}
		}finally{
			
			tracker_listeners_mon.exit();
		}	
	
public voidaddTrackerListener(org.gudy.azureus2.plugins.download.DownloadTrackerListener l)

		addTrackerListener(l, true);
	
public voidaddTrackerListener(org.gudy.azureus2.plugins.download.DownloadTrackerListener l, boolean immediateTrigger)

		try{
			tracker_listeners_mon.enter();
	
			List	new_tracker_listeners = new ArrayList( tracker_listeners );
			
			new_tracker_listeners.add( l );
			
			tracker_listeners	= new_tracker_listeners;
			
			if ( tracker_listeners.size() == 1 ){
				
				download_manager.addTrackerListener( this );
			}
		}finally{
			
			tracker_listeners_mon.exit();
		}
		
		if (immediateTrigger) {this.announceTrackerResultsToListener(l);}
	
public voidannounceResult(TRTrackerAnnouncerResponse response)

		last_announce_result.setContent( response );
		
		List	tracker_listeners_ref = tracker_listeners;
		
		for (int i=0;i<tracker_listeners_ref.size();i++){
			
			try{						
				((DownloadTrackerListener)tracker_listeners_ref.get(i)).announceResult( last_announce_result );

			}catch( Throwable e ){
				
				Debug.printStackTrace( e );
			}
		}
	
voidannounceTrackerResultsToListener(org.gudy.azureus2.plugins.download.DownloadTrackerListener l)

		l.announceResult(last_announce_result);
		l.scrapeResult(last_scrape_result);
	
public java.io.File[]calculateDefaultPaths(boolean for_moving)

  		return download_manager.calculateDefaultPaths(for_moving);
  	
public booleancanBeRemoved()

		int	dl_state = download_manager.getState();
		
		if ( 	dl_state == DownloadManager.STATE_STOPPED 	|| 
				dl_state == DownloadManager.STATE_ERROR 	||
				dl_state == DownloadManager.STATE_QUEUED ){
						
			GlobalManager globalManager = download_manager.getGlobalManager();
			
			try{
				globalManager.canDownloadManagerBeRemoved(download_manager, false, false);
				
			}catch( GlobalManagerDownloadRemovalVetoException e ){
				
				throw( new DownloadRemovalVetoException( e.getMessage(),e.isSilent()));
			}
			
		}else{
			
			throw( new DownloadRemovalVetoException( MessageText.getString("plugin.download.remove.veto.notstopped")));
		}
		
		return( true );
	
public voidcompletionChanged(DownloadManager manager, boolean bCompleted)

	
protected java.lang.StringconvertAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute)

 	if ( attribute.getName() == TorrentAttribute.TA_CATEGORY ){
  		
  		return( DownloadManagerState.AT_CATEGORY );
  		
 	}else if ( attribute.getName() == TorrentAttribute.TA_NETWORKS ){
  		
		return( DownloadManagerState.AT_NETWORKS );
		
 	}else if ( attribute.getName() == TorrentAttribute.TA_TRACKER_CLIENT_EXTENSIONS ){
  		
		return( DownloadManagerState.AT_TRACKER_CLIENT_EXTENSIONS );
	  		
	}else if ( attribute.getName() == TorrentAttribute.TA_PEER_SOURCES ){
  		
		return( DownloadManagerState.AT_PEER_SOURCES );

	}else if ( attribute.getName() == TorrentAttribute.TA_DISPLAY_NAME ){
		
		return( DownloadManagerState.AT_DISPLAY_NAME );
		
	}else if ( attribute.getName() == TorrentAttribute.TA_USER_COMMENT ){
		
		return( DownloadManagerState.AT_USER_COMMENT );	

	}else if ( attribute.getName() == TorrentAttribute.TA_RELATIVE_SAVE_PATH ){
		
		return( DownloadManagerState.AT_RELATIVE_SAVE_PATH );	
		
	}else if ( attribute.getName() == TorrentAttribute.TA_SHARE_PROPERTIES ){
  		
			// this is a share-level attribute only, not propagated to individual downloads
		
		return( null );
  		
	}else if ( attribute.getName().startsWith( "Plugin." )){
  		
		return( attribute.getName());
  		
  	}else{
  		
  		Debug.out( "Can't convert attribute '" + attribute.getName() + "'" );
  		
  		return( null );
  	}
  
protected org.gudy.azureus2.plugins.torrent.TorrentAttributeconvertAttribute(java.lang.String name)

 	if ( name.equals( DownloadManagerState.AT_CATEGORY )){
  		
  		return( TorrentManagerImpl.getSingleton().getAttribute( TorrentAttribute.TA_CATEGORY ));
  		
	}else if ( name.equals( DownloadManagerState.AT_NETWORKS )){
	  		
	  	return( TorrentManagerImpl.getSingleton().getAttribute( TorrentAttribute.TA_NETWORKS ));
	  		
	}else if ( name.equals( DownloadManagerState.AT_PEER_SOURCES )){
  		
		return( TorrentManagerImpl.getSingleton().getAttribute( TorrentAttribute.TA_PEER_SOURCES ));
		
	}else if ( name.equals( DownloadManagerState.AT_TRACKER_CLIENT_EXTENSIONS )){
  		
		return( TorrentManagerImpl.getSingleton().getAttribute( TorrentAttribute.TA_TRACKER_CLIENT_EXTENSIONS ));
	
	}else if ( name.equals ( DownloadManagerState.AT_DISPLAY_NAME)){
		
		return ( TorrentManagerImpl.getSingleton().getAttribute( TorrentAttribute.TA_DISPLAY_NAME ));
		
	}else if ( name.equals ( DownloadManagerState.AT_USER_COMMENT)){
		
		return ( TorrentManagerImpl.getSingleton().getAttribute( TorrentAttribute.TA_USER_COMMENT ));

	}else if ( name.equals ( DownloadManagerState.AT_RELATIVE_SAVE_PATH)){
		
		return ( TorrentManagerImpl.getSingleton().getAttribute( TorrentAttribute.TA_RELATIVE_SAVE_PATH ));
		
	}else if ( name.startsWith( "Plugin." )){
  		
		return( TorrentManagerImpl.getSingleton().getAttribute( name ));
	  		
  	}else{
  		
  		return( null );
  	}
  
protected intconvertState(int dm_state)

	
		// dm states: waiting -> initialising -> initialized -> 
		//		disk states: allocating -> checking -> ready ->
		// dm states: downloading -> finishing -> seeding -> stopping -> stopped
		
		// "initialize" call takes from waiting -> initialising -> waiting (no port) or initialized (ok)
		// if initialized then disk manager runs through to ready
		// "startdownload" takes ready -> dl etc.
		// "stopIt" takes to stopped which is equiv to ready
		
		int	our_state;
		
		switch( dm_state ){
			case DownloadManager.STATE_WAITING:
			{
				our_state	= ST_WAITING;
				
				break;
			}		
			case DownloadManager.STATE_INITIALIZING:
			case DownloadManager.STATE_INITIALIZED:
			case DownloadManager.STATE_ALLOCATING:
			case DownloadManager.STATE_CHECKING:
			{
				our_state	= ST_PREPARING;
					
				break;
			}
			case DownloadManager.STATE_READY:
			{
				our_state	= ST_READY;
					
				break;
			}
			case DownloadManager.STATE_DOWNLOADING:
			case DownloadManager.STATE_FINISHING:		// finishing download - transit to seeding
			{
				our_state	= ST_DOWNLOADING;
					
				break;
			}
			case DownloadManager.STATE_SEEDING:
			{
				our_state	= ST_SEEDING;
				
				break;
			}
			case DownloadManager.STATE_STOPPING:
			{
				our_state	= ST_STOPPING;
				
				break;
			}
			case DownloadManager.STATE_STOPPED:
			{
				our_state	= ST_STOPPED;
					
				break;
			}
			case DownloadManager.STATE_QUEUED:
			{
				our_state	= ST_QUEUED;
					
				break;
			}
			case DownloadManager.STATE_ERROR:
			{
				our_state	= ST_ERROR;
				
				break;
			}
			default:
			{
				our_state	= ST_ERROR;
			}
		}
		
		return( our_state );
	
protected voiddestroy()

		download_manager.removeListener( this );
	
public voiddownloadComplete(DownloadManager manager)

	
	
public voidfilePriorityChanged(DownloadManager download, org.gudy.azureus2.core3.disk.DiskManagerFileInfo file)

	  
	
public org.gudy.azureus2.plugins.download.DownloadActivationEventgetActivationState()

		return( activation_state );
	
public java.lang.StringgetAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute)

  	String	name = convertAttribute( attribute );
  	
  	if ( name != null ){
  		
  		return( download_manager.getDownloadState().getAttribute( name ));
  	}
  	
  	return( null );
  
public booleangetBooleanAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute)

	  String name = convertAttribute(attribute);
	  if (name == null) {return false;} // Default value
	  return download_manager.getDownloadState().getBooleanAttribute(name);
  
public java.lang.StringgetCategoryName()

    Category category = download_manager.getDownloadState().getCategory();
    if (category == null)
      category = CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED);

    if (category == null)
      return null;
    return category.getName();
  
public longgetCreationTime()

		return( download_manager.getCreationTime());
	
public org.gudy.azureus2.plugins.disk.DiskManagergetDiskManager()

		PeerManager	pm = getPeerManager();
		
		if ( pm != null ){
			
			return( pm.getDiskManager());
		}
		
		return( null );
	
public org.gudy.azureus2.plugins.disk.DiskManagerFileInfo[]getDiskManagerFileInfo()

		org.gudy.azureus2.core3.disk.DiskManagerFileInfo[] info = download_manager.getDiskManagerFileInfo();
		
		if ( info == null ){
			
			return( new DiskManagerFileInfo[0] );
		}
		
		DiskManagerFileInfo[]	res = new DiskManagerFileInfo[info.length];
		
		for (int i=0;i<res.length;i++){
			
			res[i] = new DiskManagerFileInfoImpl( this, info[i] );
		}
		
		return( res );
	
public DownloadManagergetDownload()

		return( download_manager );
	
public byte[]getDownloadPeerId()

    TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
    if(announcer == null) return null;
    return announcer.getPeerId();
  
public intgetDownloadRateLimitBytesPerSecond()

  		return download_manager.getStats().getDownloadRateLimitBytesPerSecond();
  	
public java.lang.StringgetErrorStateDetails()

		return( download_manager.getErrorDetails());
	
public booleangetFlag(long flag)

		return( download_manager.getDownloadState().getFlag( flag ));
	
public intgetIndex()

		GlobalManager globalManager = download_manager.getGlobalManager();
		return globalManager.getIndexOf(download_manager);
	
public intgetIntAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute)

	  String name = convertAttribute(attribute);
	  if (name == null) {return 0;} // Default value
	  return download_manager.getDownloadState().getIntAttribute(name);
  
public org.gudy.azureus2.plugins.download.DownloadAnnounceResultgetLastAnnounceResult()

		TRTrackerAnnouncer tc = download_manager.getTrackerClient();
		
		if ( tc != null ){
			
			last_announce_result.setContent( tc.getLastResponse());
		}
		
		return( last_announce_result );
	
public org.gudy.azureus2.plugins.download.DownloadScrapeResultgetLastScrapeResult()

		
		TRTrackerScraperResponse response = download_manager.getTrackerScrapeResponse();
	
		last_scrape_result.setContent( response );
		
		return( last_scrape_result );
	
public java.lang.String[]getListAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute)

	  	String	name = convertAttribute( attribute );
	  	
	  	if ( name != null ){
	  		
	  		return( download_manager.getDownloadState().getListAttribute( name ));
	  	}
	  	
	  	return( null );
  
public longgetLongAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute)

	  String name = convertAttribute(attribute);
	  if (name == null) {return 0L;} // Default value
	  return download_manager.getDownloadState().getLongAttribute(name);
  
public java.util.MapgetMapAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute)

	  	String	name = convertAttribute( attribute );
	  	
	  	if ( name != null ){
	  		
	  		return( download_manager.getDownloadState().getMapAttribute( name ));
	  	}
	  	
	  	return( null );
  
public intgetMaximumDownloadKBPerSecond()

  		return( download_manager.getStats().getDownloadRateLimitBytesPerSecond() /1024 );
  	
public java.lang.StringgetName()

		return download_manager.getDisplayName();
	
public PeerManagergetPeerManager()

 		PEPeerManager	pm = download_manager.getPeerManager();
 		
 		if ( pm == null ){
 			
 			return( null );
 		}
 		
 		return( PeerManagerImpl.getPeerManager( pm));
 	
public intgetPosition()

		return download_manager.getPosition();
	
public intgetPriority()

    return 0;
  
public java.lang.Object[]getQueryableInterfaces()

		return new Object[] { download_manager };
	
public java.lang.StringgetRelationText()

		return propogatedRelationText(download_manager);
	
public java.lang.StringgetSavePath()

		return( download_manager.getSaveLocation().toString());
 	
public intgetSeedingRank()

    return download_manager.getSeedingRank();
  
public intgetState()

		return( convertState( download_manager.getState()) );
	
public org.gudy.azureus2.plugins.download.DownloadStatsgetStats()

		return( download_stats );
	
public intgetSubState()

		int	state = getState();
		
		if ( state == ST_STOPPING ){
			
			int	substate = download_manager.getSubState();
			
			if ( substate == DownloadManager.STATE_QUEUED ){
				
				return( ST_QUEUED );
				
			}else if ( substate == DownloadManager.STATE_STOPPED ){
				
				return( ST_STOPPED );
				
			}else if ( substate == DownloadManager.STATE_ERROR ){
				
				return( ST_ERROR );
			}
		}
		
		return( state );
	
public org.gudy.azureus2.plugins.torrent.TorrentgetTorrent()

    	if (this.torrent != null) {return this.torrent;}
    	
        TOTorrent torrent = download_manager.getTorrent();
        if (torrent == null) {return null;}
        this.torrent = new TorrentImpl(torrent);
        return this.torrent;
    
public java.lang.StringgetTorrentFileName()

    return download_manager.getTorrentFileName();
  
public intgetUploadRateLimitBytesPerSecond()

      return download_manager.getStats().getUploadRateLimitBytesPerSecond();
  	
public booleanhasAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute)

	  String name = convertAttribute(attribute);
	  if (name == null) {return false;}
	  return download_manager.getDownloadState().hasAttribute(name);
  
public voidinitialize()

		int	state = download_manager.getState();
		
		if ( state == DownloadManager.STATE_WAITING ){
			
			download_manager.initialize();
			
		}else{
			
			throw( new DownloadException( "Download::initialize: download not waiting (state=" + state + ")" ));
		}
	
public booleanisChecking()

 		return( download_stats.getCheckingDoneInThousandNotation() != -1 );
 	
public booleanisComplete()

 		return download_manager.isDownloadComplete(false);
 	
public booleanisComplete(boolean bIncludeDND)

 		return download_manager.isDownloadComplete(bIncludeDND);
 	
public booleanisForceStart()

		return download_manager.isForceStart();
	
public booleanisInDefaultSaveDir()

  		return download_manager.isInDefaultSaveDir();
  	
public booleanisMessagingEnabled()

  return download_manager.isExtendedMessagingEnabled();  
public booleanisPaused()

		return( download_manager.isPaused());
	
public booleanisPersistent()

    return download_manager.isPersistent();
  
public booleanisPriorityLocked()

    return false;
  
protected voidisRemovable()

			// no sync required, see update code
		
		for (int i=0;i<removal_listeners.size();i++){
			
			try{
				((DownloadWillBeRemovedListener)removal_listeners.get(i)).downloadWillBeRemoved(this);
				
			}catch( DownloadRemovalVetoException e ){
				
				throw( e );
				
			}catch( Throwable e ){
				
				Debug.printStackTrace( e );
			}
		}
	
public booleanisStartStopLocked()

		return( download_manager.getState() == DownloadManager.STATE_STOPPED );
	
public voidmoveDataFiles(java.io.File new_parent_dir)

 		try{
 			download_manager.moveDataFiles( new_parent_dir );
 			
 		}catch( DownloadManagerException e ){
 			
 			throw( new DownloadException("move operation failed", e ));
 		}
  	
public voidmoveDataFiles(java.io.File new_parent_dir, java.lang.String new_name)

 		try{
 			download_manager.moveDataFiles( new_parent_dir, new_name );
 			
 		}catch( DownloadManagerException e ){
 			
 			throw( new DownloadException("move / rename operation failed", e ));
 		}
  	
public voidmoveDown()

		download_manager.getGlobalManager().moveDown(download_manager);
	
public voidmoveTo(int pos)

		download_manager.getGlobalManager().moveTo( download_manager, pos );
	
public voidmoveTorrentFile(java.io.File new_parent_dir)

		try{
 			download_manager.moveTorrentFile( new_parent_dir );
 			
 		}catch( DownloadManagerException e ){
 			
 			throw( new DownloadException("move operation failed", e ));
 		}  	
 	
public voidmoveUp()

		download_manager.getGlobalManager().moveUp(download_manager);
	
public voidpause()

		download_manager.pause();
	
public voidpeerAdded(PEPeer peer)

		
	
public voidpeerManagerAdded(PEPeerManager manager)

		if ( peer_listeners.size() > 0 ){
			
			PeerManager pm = PeerManagerImpl.getPeerManager( manager);
		
			for (int i=0;i<peer_listeners.size();i++){
		
				((DownloadPeerListener)peer_listeners.get(i)).peerManagerAdded( this, pm );
			}
		}
	
public voidpeerManagerRemoved(PEPeerManager manager)

		if ( peer_listeners.size() > 0 ){
			
			PeerManager pm = PeerManagerImpl.getPeerManager( manager);
		
			for (int i=0;i<peer_listeners.size();i++){
		
				((DownloadPeerListener)peer_listeners.get(i)).peerManagerRemoved( this, pm );
			}
		}	
	
public voidpeerManagerWillBeAdded(PEPeerManager manager)

	
public voidpeerRemoved(PEPeer peer)

		
	
public voidpieceAdded(PEPiece piece)

		
	
public voidpieceRemoved(PEPiece piece)

		
	
public voidpositionChanged(DownloadManager download, int oldPosition, int newPosition)

	
	for (int i = 0; i < listeners.size(); i++) {
		try {
			((DownloadListener)listeners.get(i)).positionChanged(this, oldPosition, newPosition);
		} catch (Throwable e) {
			Debug.printStackTrace( e );
		}
	}
  
public voidrecheckData()

		if ( !download_manager.canForceRecheck()){
			
			throw( new DownloadException( "Download::recheckData: download must be stopped, queued or in error state" ));
		}
		
		download_manager.forceRecheck();
	
public voidremove()

		remove( false, false );
	
public voidremove(boolean delete_torrent, boolean delete_data)

		int	dl_state = download_manager.getState();
		
		if ( 	dl_state == DownloadManager.STATE_STOPPED 	|| 
				dl_state == DownloadManager.STATE_ERROR 	||
				dl_state == DownloadManager.STATE_QUEUED ){
			
			GlobalManager globalManager = download_manager.getGlobalManager();
			
			try{
				
				globalManager.removeDownloadManager(download_manager, delete_torrent, delete_data);
				
			}catch( GlobalManagerDownloadRemovalVetoException e ){
				
				throw( new DownloadRemovalVetoException( e.getMessage()));
			}
			
		}else{
			
			throw( new DownloadRemovalVetoException( MessageText.getString("plugin.download.remove.veto.notstopped")));
		}
	
public voidremoveActivationListener(org.gudy.azureus2.plugins.download.DownloadActivationListener l)

		try{
			peer_listeners_mon.enter();

			activation_listeners.remove( l );
			
			if ( activation_listeners.size() == 0 ){
				
				download_manager.removeActivationListener( this );
			}
		}finally{
			
			peer_listeners_mon.exit();
		}
	
public voidremoveDownloadWillBeRemovedListener(org.gudy.azureus2.plugins.download.DownloadWillBeRemovedListener l)

		try{
			removal_listeners_mon.enter();
			
			List	new_removal_listeners	= new ArrayList( removal_listeners );
			
			new_removal_listeners.remove(l);
			
			removal_listeners	= new_removal_listeners;
			
		}finally{
			
			removal_listeners_mon.exit();
		}
	
public voidremoveListener(org.gudy.azureus2.plugins.download.DownloadListener l)

		try{
			listeners_mon.enter();
			
			List	new_listeners	= new ArrayList(listeners);
			
			new_listeners.remove(l);
			
			listeners	= new_listeners;
		}finally{
			
			listeners_mon.exit();
		}
	
public voidremovePeerListener(org.gudy.azureus2.plugins.download.DownloadPeerListener l)

		try{
			peer_listeners_mon.enter();

			List	new_peer_listeners	= new ArrayList( peer_listeners );
			
			new_peer_listeners.remove( l );
			
			peer_listeners	= new_peer_listeners;
			
			if ( peer_listeners.size() == 0 ){
				
				download_manager.removePeerListener( this );
			}
		}finally{
			
			peer_listeners_mon.exit();
		}
	
public voidremovePropertyListener(org.gudy.azureus2.plugins.download.DownloadPropertyListener l)

		try{
			tracker_listeners_mon.enter();
			
			List	new_property_listeners	= new ArrayList( property_listeners );
			
			new_property_listeners.remove( l );
			
			property_listeners	= new_property_listeners;
			
			if ( property_listeners.size() == 0 ){
				
				download_manager.getDownloadState().removeListener( this );
			}
		}finally{
			
			tracker_listeners_mon.exit();
		}		
	
public voidremoveTrackerListener(org.gudy.azureus2.plugins.download.DownloadTrackerListener l)

		try{
			tracker_listeners_mon.enter();
			
			List	new_tracker_listeners	= new ArrayList( tracker_listeners );
			
			new_tracker_listeners.remove( l );
			
			tracker_listeners	= new_tracker_listeners;
			
			if ( tracker_listeners.size() == 0 ){
				
				download_manager.removeTrackerListener( this );
			}
		}finally{
			
			tracker_listeners_mon.exit();
		}
	
public voidrenameDownload(java.lang.String new_name)

		try {download_manager.renameDownload(new_name);}
		catch (DownloadManagerException e) {
			throw new DownloadException("rename operation failed", e);
		}
	
public voidrequestTrackerAnnounce()

 		download_manager.requestTrackerAnnounce( false );
 	
public voidrequestTrackerAnnounce(boolean immediate)

		download_manager.requestTrackerAnnounce( immediate );
	
public voidrequestTrackerScrape(boolean immediate)

		download_manager.requestTrackerScrape( immediate );
	
public voidrestart()

		int	state = download_manager.getState();
		
		if ( 	state == DownloadManager.STATE_STOPPED ||
				state == DownloadManager.STATE_QUEUED ){
			
			download_manager.setStateWaiting();
			
		}else{
			
			throw( new DownloadException( "Download::restart: download already running (state=" + state + ")" ));
		}
	
public voidresume()

		download_manager.resume();
	
public voidscrapeResult(TRTrackerScraperResponse response)

		last_scrape_result.setContent( response );
		
		for (int i=0;i<tracker_listeners.size();i++){
			
			try{						
				((DownloadTrackerListener)tracker_listeners.get(i)).scrapeResult( last_scrape_result );

			}catch( Throwable e ){
				
				Debug.printStackTrace( e );
			}
		}
	
public voidsetAnnounceResult(org.gudy.azureus2.plugins.download.DownloadAnnounceResult result)

		download_manager.setAnnounceResult( result );
	
public voidsetAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute, java.lang.String value)

 	String	name = convertAttribute( attribute );
  	
  	if ( name != null ){

  		download_manager.getDownloadState().setAttribute( name, value );
  	}
  
public voidsetBooleanAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute, boolean value)

	  String name = convertAttribute(attribute);
	  if (name != null) {
		  download_manager.getDownloadState().setBooleanAttribute(name, value);
	  }
  
public voidsetCategory(java.lang.String sName)

    Category category = CategoryManager.getCategory(sName);
    if (category == null)
      category = CategoryManager.createCategory(sName);
    download_manager.getDownloadState().setCategory(category);
  
public voidsetDownloadRateLimitBytesPerSecond(int max_rate_bps)

  		download_manager.getStats().setDownloadRateLimitBytesPerSecond( max_rate_bps );
  	
public voidsetFlag(long flag, boolean set)

		download_manager.getDownloadState().setFlag(flag, set);
	
public voidsetForceStart(boolean forceStart)

		download_manager.setForceStart(forceStart);
	
public voidsetIntAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute, int value)

	  String name = convertAttribute(attribute);
	  if (name != null) {
		  download_manager.getDownloadState().setIntAttribute(name, value);
	  }
  
public voidsetListAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute, java.lang.String[] value)

	  String name = convertAttribute(attribute);
	  
	  if (name != null) {
		  download_manager.getDownloadState().setListAttribute(name, value);
	  }
  
public voidsetLongAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute, long value)

	  String name = convertAttribute(attribute);
	  if (name != null) {
		  download_manager.getDownloadState().setLongAttribute(name, value);
	  }
  
public voidsetMapAttribute(org.gudy.azureus2.plugins.torrent.TorrentAttribute attribute, java.util.Map value)

	  	String	name = convertAttribute( attribute );
	  	
	  	if ( name != null ){
			
	  			// gotta clone before updating in case user has read values and then just
	  			// updated them - setter code optimises out sets of the same values...
	  		
			download_manager.getDownloadState().setMapAttribute( name, BEncoder.cloneMap( value ));
	  	}
  
public voidsetMaximumDownloadKBPerSecond(int kb)

         if(kb==-1){
            Debug.out("setMaximiumDownloadKBPerSecond got value (-1) ZERO_DOWNLOAD. (-1)"+
                "does not work through this method, use getDownloadRateLimitBytesPerSecond() instead.");
         }//if

         download_manager.getStats().setDownloadRateLimitBytesPerSecond( kb < 0 ? 0 : kb*1024 );
 	
public voidsetMessagingEnabled(boolean enabled)

	  throw new RuntimeException("setMessagingEnabled is in the process of being removed - if you are seeing this error, let the Azureus developers know that you need this method to stay!");
    //download_manager.setAZMessagingEnabled( enabled );
  
public voidsetPosition(int newPosition)

		download_manager.setPosition(newPosition);
	
public voidsetPriority(int priority)

  
public voidsetScrapeResult(org.gudy.azureus2.plugins.download.DownloadScrapeResult result)

		download_manager.setScrapeResult( result );
	
public voidsetSeedingRank(int rank)

		download_manager.setSeedingRank(rank);
	
public voidsetSessionAuthenticator(org.gudy.azureus2.plugins.download.session.SessionAuthenticator auth)

    //TODO
  
public voidsetUploadRateLimitBytesPerSecond(int max_rate_bps)

      download_manager.getStats().setUploadRateLimitBytesPerSecond( max_rate_bps );
  	
public voidstart()

		int	state = download_manager.getState();
		
		if ( state == DownloadManager.STATE_READY ){
						
			download_manager.startDownload();
										
		}else{
			
			throw( new DownloadException( "Download::start: download not ready (state=" + state + ")" ));
		}
	
public voidstateChanged(DownloadManager manager, int state)

		int	prev_state 	= latest_state;
		
		latest_state	= convertState(state);
		
		// System.out.println("Plug: dl = " + getName() + ", prev = " + prev_state + ", curr = " + latest_state + ", signalled state = " + state);
		
		boolean curr_forcedStart = isForceStart();
	
		if ( prev_state != latest_state || latest_forcedStart != curr_forcedStart ){
			
			latest_forcedStart = curr_forcedStart;
			
			for (int i=0;i<listeners.size();i++){
				
				try{
					((DownloadListener)listeners.get(i)).stateChanged( this, prev_state, latest_state );
				
				}catch( Throwable e ){
					
					Debug.printStackTrace( e );
				}
			}
		}
	
public voidstateChanged(DownloadManagerState state, DownloadManagerStateEvent event)

		final int type = event.getType();
		
		if ( 	type == DownloadManagerStateEvent.ET_ATTRIBUTE_WRITTEN ||
				type == DownloadManagerStateEvent.ET_ATTRIBUTE_WILL_BE_READ 	){
			
			String	name = (String)event.getData();
			
			List	property_listeners_ref = property_listeners;
			
			final TorrentAttribute	attr = convertAttribute( name );
			
			if ( attr != null ){
				
				for (int i=0;i<property_listeners_ref.size();i++){
					
					try{						
						((DownloadPropertyListener)property_listeners_ref.get(i)).propertyChanged(
								this,
								new DownloadPropertyEvent()
								{
									public int
									getType()
									{
										return( type==DownloadManagerStateEvent.ET_ATTRIBUTE_WRITTEN
													?DownloadPropertyEvent.PT_TORRENT_ATTRIBUTE_WRITTEN
													:DownloadPropertyEvent.PT_TORRENT_ATTRIBUTE_WILL_BE_READ	);
									}
									
									public Object
									getData()
									{
										return( attr );
									}
								});

					}catch( Throwable e ){
						
						Debug.printStackTrace( e );
					}
				}
			}			
		}
	
public voidstop()

		if ( download_manager.getState() != DownloadManager.STATE_STOPPED){
			
			download_manager.stopIt( DownloadManager.STATE_STOPPED, false, false );
			
		}else{
			
			throw( new DownloadException( "Download::stop: download already stopped" ));
		}
	
public voidstopAndQueue()

		if ( download_manager.getState() != DownloadManager.STATE_QUEUED){
						
			download_manager.stopIt( DownloadManager.STATE_QUEUED, false, false );
			
		}else{
			
			throw( new DownloadException( "Download::stopAndQueue: download already queued" ));
		}
	
public voidtorrentChanged()

		TRTrackerAnnouncer	client = download_manager.getTrackerClient();
		
		if ( client != null ){
			
			client.resetTrackerUrl(true);
		}