FileDocCategorySizeDatePackage
DownloadManagerEnhancer.javaAPI DocAzureus 3.0.3.47438Tue Sep 11 17:49:44 BST 2007com.aelitis.azureus.core.download

DownloadManagerEnhancer

public class DownloadManagerEnhancer extends Object

Fields Summary
public static final int
TICK_PERIOD
public static final int
PUBLISHING_CHECK_PERIOD
public static final int
PUBLISHING_CHECK_TICKS
private static DownloadManagerEnhancer
singleton
private com.aelitis.azureus.core.AzureusCore
core
private Map
download_map
private boolean
progressive_enabled
Constructors Summary
protected DownloadManagerEnhancer(com.aelitis.azureus.core.AzureusCore _core)

	
	
	
			 
	
		core	= _core;
		
		core.getGlobalManager().addListener(
			new GlobalManagerListener()
			{
				public void
				downloadManagerAdded(
					DownloadManager	dm )
				{
					// Don't auto-add to download_map. getEnhancedDownload will
					// take care of it later if we ever need the download
				}
					
				public void
				downloadManagerRemoved(
					DownloadManager	dm )
				{
					EnhancedDownloadManager	edm;
					
					synchronized( download_map ){
						
						edm = (EnhancedDownloadManager)download_map.remove( dm );
					}
					
					if ( edm != null ){
						
						edm.destroy();
					}
				}
					
				public void
				destroyInitiated()
				{
					// resume any downloads we paused
					core.getGlobalManager().resumeDownloads();
				}
					
				public void
				destroyed()
				{
				}
			  
			    public void 
			    seedingStatusChanged( 
			    	boolean seeding_only_mode )
			    {
			    }
			});
		
		PlatformTorrentUtils.addListener(
			new MetaDataUpdateListener()
			{
				public void 
				metaDataUpdated(
					TOTorrent torrent )
				{
					 DownloadManager dm = core.getGlobalManager().getDownloadManager( torrent );

					 if ( dm == null ){
						 
						 Debug.out( "Meta data update: download not found for " + torrent );
						 
					 }else{
						
						 EnhancedDownloadManager edm = getEnhancedDownload( dm );
						 
						 if ( edm != null ){
							 
							 edm.refreshMetaData();
						 }
					 }
				}
			});
		
		SimpleTimer.addPeriodicEvent(
				"DownloadManagerEnhancer:speedChecker",
				TICK_PERIOD,
				new TimerEventPerformer()
				{
					private int tick_count;
					
					public void 
					perform(
						TimerEvent event ) 
					{
						tick_count++;
						
						boolean	check_publish = tick_count % PUBLISHING_CHECK_TICKS == 0;
						
						List	downloads = core.getGlobalManager().getDownloadManagers();
						
						for ( int i=0;i<downloads.size();i++){
							
							DownloadManager download = (DownloadManager)downloads.get(i);
							
							int	state = download.getState();
							
							if ( 	state == DownloadManager.STATE_DOWNLOADING ||
									state == DownloadManager.STATE_SEEDING ){
								
								EnhancedDownloadManager edm = getEnhancedDownload( download );
								if (edm == null) {
									return;
								}
								
								edm.updateStats( tick_count );
							
								if ( 	state == DownloadManager.STATE_SEEDING &&
										check_publish ){
											
									edm.checkPublishing();
								}
							}
						}
					}
				});
		
			// listener to pick up on streams kicked off externally
		
		DiskManagerChannelImpl.addListener(
			new DiskManagerChannelImpl.channelCreateListener()
			{
				public void
				channelCreated(
					DiskManagerChannel	channel )
				{
					try{
						EnhancedDownloadManager edm = 
							getEnhancedDownload(
									PluginCoreUtils.unwrap(channel.getFile().getDownload()));

						if (edm == null) {
							return;
						}

						if ( !edm.getProgressiveMode()){
							
							if ( edm.supportsProgressiveMode()){
								
								Debug.out( "Enabling progressive mode for '" + edm.getName() + "' due to external stream" );
								
								edm.setProgressiveMode( true );
							}
						}
					}catch( Throwable e ){
						
						Debug.printStackTrace(e);
					}
				}
			});
	
Methods Summary
public org.gudy.azureus2.core3.download.DownloadManagerfindDownloadManager(java.lang.String hash)

param
hash
return
since
3.0.1.7

		synchronized (download_map) {

			if (download_map == null) {
				return null;
			}

			for (Iterator iter = download_map.keySet().iterator(); iter.hasNext();) {
				DownloadManager dm = (DownloadManager) iter.next();

				TOTorrent torrent = dm.getTorrent();
				if (PlatformTorrentUtils.isContent(torrent, true)) {
					String thisHash = PlatformTorrentUtils.getContentHash(torrent);
					if (hash.equals(thisHash)) {
						return dm;
					}
				}
			}
		}
		return null;
	
public EnhancedDownloadManagergetEnhancedDownload(byte[] hash)

		DownloadManager dm = core.getGlobalManager().getDownloadManager(new HashWrapper( hash ));
		
		if ( dm == null ){
			
			return( null );
		}
		
		return( getEnhancedDownload( dm ));
	
public EnhancedDownloadManagergetEnhancedDownload(org.gudy.azureus2.core3.download.DownloadManager manager)

		DownloadManager dm2 = manager.getGlobalManager().getDownloadManager(manager.getTorrent());
		if (dm2 != manager) {
			return null;
		}

		synchronized( download_map ){
			
			EnhancedDownloadManager	res = (EnhancedDownloadManager)download_map.get( manager );
			
			if ( res == null ){
				
				res = new EnhancedDownloadManager( DownloadManagerEnhancer.this, manager );
				
				download_map.put( manager, res );
			}
			
			return( res );
		}
	
public static synchronized com.aelitis.azureus.core.download.DownloadManagerEnhancergetSingleton()

		return( singleton );
	
public static synchronized com.aelitis.azureus.core.download.DownloadManagerEnhancerinitialise(com.aelitis.azureus.core.AzureusCore core)

	
	   
	
				 
	
		if ( singleton == null ){
			
			singleton	= new DownloadManagerEnhancer( core );
		}
		
		return( singleton );
	
protected booleanisProgressiveAvailable()

		if ( progressive_enabled ){
			
			return( true );
		}
	
		PluginInterface	ms_pi = core.getPluginManager().getPluginInterfaceByID( "azupnpav" );
		
		if ( ms_pi != null ){
			
			progressive_enabled = ms_pi.isOperational();
		}
		
		return( progressive_enabled );