FileDocCategorySizeDatePackage
DiskManagerRecheckScheduler.javaAPI DocAzureus 3.0.3.44767Tue May 29 14:07:24 BST 2007org.gudy.azureus2.core3.disk.impl

DiskManagerRecheckScheduler

public class DiskManagerRecheckScheduler extends Object

Fields Summary
private static boolean
friendly_hashing
private static boolean
smallest_first
private List
instances
private org.gudy.azureus2.core3.util.AEMonitor
instance_mon
Constructors Summary
Methods Summary
protected booleangetPermission(DiskManagerRecheckInstance instance)

		boolean	result 	= false;
		int		delay	= 250;
		
		try{
			instance_mon.enter();

			if ( instances.get(0) == instance ){
					    
				boolean	low_priority = instance.isLowPriority();
				
					// defer low priority activities if we are running a real-time task
				
				if ( low_priority && ConcurrentHasher.getSingleton().isRealTimeTaskActive()){
					
					result = false;
					
				}else{
					
		            if ( friendly_hashing ){
		            	
		            	delay	= 0;	// delay introduced elsewhere
		            	
		            }else if ( !low_priority ){
		            	
		            	delay	= 1;	// high priority recheck, just a smidge of a delay
		            	
		            }else{
		            	
			            	//delay a bit normally anyway, as we don't want to kill the user's system
			            	//during the post-completion check (10k of piece = 1ms of sleep)
		            	
		            	delay = instance.getPieceLength() /1024 /10;
		              
		            	delay = Math.min( delay, 409 );
		              
		            	delay = Math.max( delay, 12 );
	  				}
					
		            result	= true;
				}
			}
		}finally{
			
			instance_mon.exit();
		}
		
		if ( delay > 0 ){
			
			try{
				Thread.sleep( delay );
				
			}catch( Throwable e ){
				
			}
		}
		
		return( result );
	
public DiskManagerRecheckInstanceregister(DiskManagerHelper helper, boolean low_priority)

	
	
	 
	
			
						 
	
		try{
			instance_mon.enter();
			
			DiskManagerRecheckInstance	res = 
				new DiskManagerRecheckInstance( 
						this, 
						helper.getTorrent().getSize(),
						(int)helper.getTorrent().getPieceLength(),
						low_priority );
			
			instances.add( res );
			
			if ( smallest_first ){
				
				Collections.sort(
						instances,
						new Comparator()
						{
							public int
							compare(
								Object	o1,
								Object	o2 )
							{
								long	comp = ((DiskManagerRecheckInstance)o1).getMetric() - ((DiskManagerRecheckInstance)o2).getMetric();
								
								if ( comp < 0 ){
									
									return( -1 );
									
								}else if ( comp == 0 ){
									
									return( 0 );
									
								}else{
									return( 1 );
								}
							}
						});
			}
			
			return( res );
			
		}finally{
			
			instance_mon.exit();
		}
	
protected voidunregister(DiskManagerRecheckInstance instance)

		try{
			instance_mon.enter();
			
			instances.remove( instance );
		}finally{
			
			instance_mon.exit();
		}