FileDocCategorySizeDatePackage
ResourceDownloaderRetryImpl.javaAPI DocAzureus 3.0.3.44746Thu Feb 09 19:42:50 GMT 2006org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader

ResourceDownloaderRetryImpl

public class ResourceDownloaderRetryImpl extends ResourceDownloaderBaseImpl implements ResourceDownloaderListener
author
parg

Fields Summary
protected ResourceDownloaderBaseImpl
delegate
protected int
retry_count
protected boolean
cancelled
protected ResourceDownloader
current_downloader
protected int
done_count
protected Object
result
protected AESemaphore
done_sem
protected long
size
Constructors Summary
public ResourceDownloaderRetryImpl(ResourceDownloaderBaseImpl _parent, ResourceDownloader _delegate, int _retry_count)

	
	
	
			
				
								 
	
		super( _parent );
		
		delegate		= (ResourceDownloaderBaseImpl)_delegate;
		
		delegate.setParent( this );

		retry_count		= _retry_count;
	
Methods Summary
public voidasyncDownload()

		try{
			this_mon.enter();
			
			if ( done_count == retry_count || cancelled ){
				
				done_sem.release();
				
				informFailed((ResourceDownloaderException)result);
				
			}else{
			
				done_count++;
				
				if ( done_count > 1 ){
					
					informActivity( getLogIndent() + "  attempt " + done_count + " of " + retry_count );
				}
				
				current_downloader = delegate.getClone( this );
				
				current_downloader.addListener( this );
				
				current_downloader.asyncDownload();
			}
		}finally{
			
			this_mon.exit();
		}
	
public voidcancel()

		setCancelled();
		
		try{
			this_mon.enter();
		
			result	= new ResourceDownloaderException( "Download cancelled");
			
			cancelled	= true;
			
			informFailed((ResourceDownloaderException)result );
			
			done_sem.release();
			
			if ( current_downloader != null ){
				
				current_downloader.cancel();
			}
		}finally{
			
			this_mon.exit();
		}
	
public booleancompleted(ResourceDownloader downloader, java.io.InputStream data)

		if ( informComplete( data )){
			
			result	= data;
			
			done_sem.release();
			
			return( true );
		}
		
		return( false );
	
public java.io.InputStreamdownload()

		asyncDownload();
		
		done_sem.reserve();
		
		if ( result instanceof InputStream ){
			
			return((InputStream)result);
		}
		
		throw((ResourceDownloaderException)result);
	
public voidfailed(ResourceDownloader downloader, ResourceDownloaderException e)

		result		= e;
		
		asyncDownload();
	
public ResourceDownloaderBaseImplgetClone(ResourceDownloaderBaseImpl parent)

		ResourceDownloaderRetryImpl c =  new ResourceDownloaderRetryImpl( parent, delegate.getClone( this ), retry_count );
		
		c.setSize(size);
		
		c.setProperties( this );

		return( c );
	
public java.lang.StringgetName()

		return( delegate.getName() + ", retry=" + retry_count );
	
public longgetSize()

	
		if ( size != -2 ){
			
			return( size );
		}
		
		try{
			for (int i=0;i<retry_count;i++){
				
				try{
					ResourceDownloaderBaseImpl c =  delegate.getClone( this );
					
					addReportListener( c );
					
					size = c.getSize();
				
					setProperties( c );
					
					return( size );
					
				}catch( ResourceDownloaderException e ){
					
					if ( i == retry_count - 1 ){
						
						throw( e );
					}
				}
			}
		}finally{
			
			if ( size == -2 ){
				
				size = -1;
			}
			
			setSize( size );
		}

		return( size );
	
protected voidsetProperty(java.lang.String name, java.lang.Object value)

		setPropertySupport( name, value );
		
		delegate.setProperty( name, value );
	
protected voidsetSize(long l)

		size	= l;
		
		if ( size >= 0 ){
			
			delegate.setSize( size );
		}