FileDocCategorySizeDatePackage
UpdateAutoDownloader.javaAPI DocAzureus 3.0.3.45044Fri Sep 21 14:13:58 BST 2007org.gudy.azureus2.ui.swt.update

UpdateAutoDownloader

public class UpdateAutoDownloader extends Object implements org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloaderListener
author
TuxPaper
created
Feb 25, 2007

Fields Summary
private final org.gudy.azureus2.plugins.update.Update[]
updates
private ArrayList
downloaders
private Iterator
iterDownloaders
private final cbCompletion
completionCallback
Constructors Summary
public UpdateAutoDownloader(org.gudy.azureus2.plugins.update.Update[] updates, cbCompletion completionCallback)

param
us

		this.updates = updates;
		this.completionCallback = completionCallback;
		downloaders = new ArrayList();

		start();
	
Methods Summary
private voidallDownloadsComplete()

since
3.0.0.7

		boolean bRequiresRestart = false;
		boolean bHadMandatoryUpdates = false;
		
		for (int i = 0; i < updates.length; i++) {
			Update update = updates[i];
				// updates with no downloaders exist for admin purposes only
			if ( update.getDownloaders().length > 0){
				if (update.getRestartRequired() != Update.RESTART_REQUIRED_NO) {
					bRequiresRestart = true;
				}
				if ( update.isMandatory()){
					bHadMandatoryUpdates = true;
				}
			}
		}

		completionCallback.allUpdatesComplete(bRequiresRestart,bHadMandatoryUpdates);
	
public booleancompleted(org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloader downloader, java.io.InputStream data)

		downloader.removeListener(this);
		if (!nextUpdate()) {
			// fire in another thread so completed function can exit
			AEThread thread = new AEThread("AllDownloadsComplete", true) {
				public void runSupport() {
					allDownloadsComplete();
				}
			};
			thread.start();
		}
		return true;
	
public voidfailed(org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloader downloader, org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloaderException e)

		downloader.removeListener(this);
		iterDownloaders.remove();
		nextUpdate();
	
private booleannextUpdate()

since
3.0.0.7

		if (iterDownloaders.hasNext()) {
			ResourceDownloader downloader = (ResourceDownloader) iterDownloaders.next();
			downloader.addListener(this);
			downloader.asyncDownload();
			return true;
		}
		return false;
	
public voidreportActivity(org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloader downloader, java.lang.String activity)

	
public voidreportAmountComplete(org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloader downloader, long amount)

	
public voidreportPercentComplete(org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloader downloader, int percentage)

	
private voidstart()

		for (int i = 0; i < updates.length; i++) {
			Update update = updates[i];
			ResourceDownloader[] rds = update.getDownloaders();
			for (int j = 0; j < rds.length; j++) {
				ResourceDownloader rd = rds[j];
				downloaders.add(rd);
			}
		}

		iterDownloaders = downloaders.iterator();
		nextUpdate();