FileDocCategorySizeDatePackage
UpdateManagerImpl.javaAPI DocAzureus 3.0.3.47223Thu Jan 11 10:15:18 GMT 2007org.gudy.azureus2.pluginsimpl.local.update

UpdateManagerImpl

public class UpdateManagerImpl extends Object implements UpdateManager
author
parg

Fields Summary
protected static UpdateManagerImpl
singleton
protected com.aelitis.azureus.core.AzureusCore
azureus_core
protected List
components
protected List
listeners
protected List
verification_listeners
protected List
installers
protected org.gudy.azureus2.core3.util.AEMonitor
this_mon
Constructors Summary
protected UpdateManagerImpl(com.aelitis.azureus.core.AzureusCore _azureus_core)


	
	
				 
	
		azureus_core	= _azureus_core;
		
		UpdateInstallerImpl.checkForFailedInstalls( this );
		
			// cause the platform manager to register any updateable components
		
		try{
			PlatformManagerFactory.getPlatformManager();
			
		}catch( Throwable e ){
		
		}
	
Methods Summary
public voidaddListener(UpdateManagerListener l)

		listeners.add(l);
	
public voidaddVerificationListener(UpdateManagerVerificationListener l)

		verification_listeners.add( l );
	
public voidapplyUpdates(boolean restart_after)

		try{
			if ( restart_after ){
				
				azureus_core.requestRestart();
				
			}else{
				
				azureus_core.requestStop();
			}
		}catch( Throwable e ){
			
			throw( new UpdateException( "UpdateManager:applyUpdates fails", e ));
		}
	
public UpdateCheckInstancecreateEmptyUpdateCheckInstance(int type, java.lang.String name)

		try{
			this_mon.enter();
	
			UpdatableComponentImpl[]	comps = new UpdatableComponentImpl[0];
			
			UpdateCheckInstance	res = new UpdateCheckInstanceImpl( this, type, name, comps );
			
			for (int i=0;i<listeners.size();i++){
				
				((UpdateManagerListener)listeners.get(i)).checkInstanceCreated( res );
			}
			
			return( res );
			
		}finally{
			
			this_mon.exit();
		}		
	
public UpdateInstallercreateInstaller()

		UpdateInstaller	installer = new UpdateInstallerImpl( this );
		
		installers.add( installer );
		
		return( installer );
	
public UpdateCheckInstancecreateUpdateCheckInstance()

		return( createUpdateCheckInstance( UpdateCheckInstance.UCI_UPDATE, "" ));
	
public UpdateCheckInstancecreateUpdateCheckInstance(int type, java.lang.String name)

		try{
			this_mon.enter();
	
			UpdatableComponentImpl[]	comps = new UpdatableComponentImpl[components.size()];
			
			components.toArray( comps );
			
			UpdateCheckInstance	res = new UpdateCheckInstanceImpl( this, type, name, comps );
			
			for (int i=0;i<listeners.size();i++){
				
				((UpdateManagerListener)listeners.get(i)).checkInstanceCreated( res );
			}
			
			return( res );
			
		}finally{
			
			this_mon.exit();
		}
	
public java.lang.StringgetInstallDir()

		String	str = SystemProperties.getApplicationPath();
		
		if ( str.endsWith(File.separator)){
			
			str = str.substring(0,str.length()-1);
		}
		
		return( str );
	
public UpdateInstaller[]getInstallers()

		UpdateInstaller[]	res = new UpdateInstaller[installers.size()];
		
		installers.toArray( res );
		
		return( res );
	
public static UpdateManagergetSingleton(com.aelitis.azureus.core.AzureusCore core)

		if ( singleton == null ){
			
			singleton = new UpdateManagerImpl( core );
		}
		
		return( singleton );
	
public java.lang.StringgetUserDir()

		String	str = SystemProperties.getUserPath();
		
		if ( str.endsWith(File.separator)){
			
			str = str.substring(0,str.length()-1);
		}
		
		return( str );	
	
public voidregisterUpdatableComponent(UpdatableComponent component, boolean mandatory)

		try{
			this_mon.enter();
			
			components.add( new UpdatableComponentImpl( component, mandatory ));
		}finally{
			
			this_mon.exit();
		}
	
public voidremoveListener(UpdateManagerListener l)

		listeners.remove(l);
	
public voidremoveVerificationListener(UpdateManagerVerificationListener l)

		verification_listeners.add( l );
	
public voidrestart()

		applyUpdates( true );
	
public java.io.InputStreamverifyData(Update update, java.io.InputStream is, boolean force)

		boolean	queried 	= false;
		boolean	ok			= false;
		Throwable	failure	= null;
		
		try{
			File	temp = AETemporaryFileHandler.createTempFile();
			
			FileUtil.copyFile( is, temp );
			
			try{
				AEVerifier.verifyData( temp );
			
				ok	= true;
				
				return( new FileInputStream( temp ));

			}catch( AEVerifierException e ){
								
				if ( (!force) && e.getFailureType() == AEVerifierException.FT_SIGNATURE_MISSING ){
					
					for (int i=0;i<verification_listeners.size();i++){
						
						try{
							queried	= true;
							
							if ( ((UpdateManagerVerificationListener)verification_listeners.get(i)).acceptUnVerifiedUpdate(
									update )){
								
								ok	= true;
								
								return( new FileInputStream( temp ));
							}
						}catch( Throwable f ){
							
							Debug.printStackTrace(f);
						}
					}
				}
				
				failure	= e;
				
				throw( e );
			}
		}catch( UpdateException e ){

			failure	= e;
			
			throw( e );
				
		}catch( Throwable e ){
			
			failure	= e;
			
			throw( new UpdateException( "Verification failed", e ));
			
		}finally{
			
			if ( !( queried || ok )){
				
				if ( failure == null ){
					
					failure = new UpdateException( "Verification failed" );
				}
				
				for (int i=0;i<verification_listeners.size();i++){
					
					try{
						((UpdateManagerVerificationListener)verification_listeners.get(i)).verificationFailed( update, failure );
	
					}catch( Throwable f ){
						
						Debug.printStackTrace(f);
					}
				}
			}
		}