FileDocCategorySizeDatePackage
GlobalManagerHostSupport.javaAPI DocAzureus 3.0.3.43245Thu Feb 09 19:43:10 GMT 2006org.gudy.azureus2.core3.global.impl

GlobalManagerHostSupport

public class GlobalManagerHostSupport extends Object implements TRHostTorrentFinder

Fields Summary
protected GlobalManager
gm
protected TRHost
host
Constructors Summary
protected GlobalManagerHostSupport(GlobalManager _gm)

		gm		= _gm;
		
	    host = TRHostFactory.getSingleton();
		  
		host.initialise( this );
	
Methods Summary
protected voiddestroy()

			
		host.close();
	
public org.gudy.azureus2.core3.torrent.TOTorrentlookupTorrent(byte[] hash)

		List	managers = gm.getDownloadManagers();
		
		for (int i=0;i<managers.size();i++){
			
			DownloadManager	dm = (DownloadManager)managers.get(i);
			
			TOTorrent t = dm.getTorrent();
			
			if ( t != null ){
				
				try{
					if ( Arrays.equals( hash, t.getHash())){
						
						return( t );
					}
				}catch( TOTorrentException e ){
					
					Debug.printStackTrace( e );
				}
			}
		}
		
		return( null );
	
protected voidtorrentRemoved(java.lang.String torrent_file_str, org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		TRHostTorrent	host_torrent = host.getHostTorrent( torrent );
		
		if ( host_torrent != null ){
			
				// it we remove a torrent while it is hosted then we flip it into passive mode to
				// keep it around in a sensible state
			
				// we've got to ensure that the torrent's file location is available in the torrent itself
				// as we're moving from download-managed persistence to host managed :(
			
				// check file already exists - might have already been deleted as in the
				// case of shared resources
			
			File	torrent_file = new File( torrent_file_str );
			
			if ( torrent_file.exists()){
				
				try{
					TorrentUtils.writeToFile( host_torrent.getTorrent(), torrent_file, false );
				
					host_torrent.setPassive( true );
					
				}catch( Throwable e ){
					
					Debug.out( "Failed to make torrent '" + torrent_file_str + "' passive: " + Debug.getNestedExceptionMessage(e));
				}
			}
		}