FileDocCategorySizeDatePackage
PluginManagerImpl.javaAPI DocAzureus 3.0.3.46634Thu Jun 15 06:41:18 BST 2006org.gudy.azureus2.pluginsimpl.local

PluginManagerImpl

public class PluginManagerImpl extends PluginManager
author
parg

Fields Summary
protected static boolean
running
protected static PluginManagerImpl
singleton
protected static org.gudy.azureus2.core3.util.AEMonitor
class_mon
protected static AzureusCore
azureus_core
protected PluginInitializer
pi
Constructors Summary
protected PluginManagerImpl(PluginInitializer _pi)

		pi		= _pi;
	
Methods Summary
public voidfirePluginEvent(int ev)

		PluginInitializer.fireEvent( ev );
	
public PluginInterfacegetDefaultPluginInterface()

		return( PluginInitializer.getDefaultInterface());
	
public org.gudy.azureus2.plugins.installer.PluginInstallergetPluginInstaller()

		return( PluginInstallerImpl.getSingleton(this));
	
public PluginInterfacegetPluginInterfaceByClass(java.lang.String class_name)

		PluginInterface[]	p = getPluginInterfaces();
		
		for (int i=0;i<p.length;i++){
			
			if ( p[i].getPlugin().getClass().getName().equals( class_name )){
				
				return( p[i]);
			}
		}
		
		return( null );
	
public PluginInterfacegetPluginInterfaceByClass(java.lang.Class c)

		PluginInterface[]	p = getPluginInterfaces();
		
		for (int i=0;i<p.length;i++){
			
			if ( p[i].getPlugin().getClass().equals( c )){
				
				return( p[i]);
			}
		}
		
		return( null );
	
public PluginInterfacegetPluginInterfaceByID(java.lang.String id)

		PluginInterface[]	p = getPluginInterfaces();
		
		for (int i=0;i<p.length;i++){
			
			if ( p[i].getPluginID().equalsIgnoreCase( id )){
				
				return( p[i]);
			}
		}
		
		return( null );
	
public PluginInterface[]getPluginInterfaces()

		List	l = PluginInitializer.getPluginInterfaces();
		
		PluginInterface[]	res = new PluginInterface[l.size()];
		
		l.toArray(res);
		
		return( res );
	
public PluginInterface[]getPlugins()

		return( pi.getPlugins());
	
protected static org.gudy.azureus2.pluginsimpl.local.PluginManagerImplgetSingleton(PluginInitializer pi)

	
	  
	
			 
	
		try{
			class_mon.enter();
			
			if ( singleton == null ){
				
				singleton = new PluginManagerImpl( pi );
			}
			
			return( singleton );
			
		}finally{
			
			class_mon.exit();
		}
	
public voidrefreshPluginList()

		List loadedPlugins = pi.loadPlugins(pi.getAzureusCore(), true);
		for (Iterator iter = loadedPlugins.iterator(); iter.hasNext();) {
			PluginInterfaceImpl plugin = (PluginInterfaceImpl) iter.next();
			if (!plugin.isOperational()) {
				try {
					pi.reloadPlugin(plugin);
				} catch (PluginException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	
public static voidregisterPlugin(java.lang.Class plugin_class)

		PluginInitializer.queueRegistration( plugin_class );
	
public static voidregisterPlugin(Plugin plugin, java.lang.String id)

		PluginInitializer.queueRegistration( plugin, id );
	
public static voidrestartAzureus()

		if ( !running ){
			
			throw( new RuntimeException( "Azureus is not running"));
		}
		
		try{
			azureus_core.requestRestart();
			
		}catch( Throwable e ){
							
			throw( new PluginException( "PluginManager: Azureus restart action failed", e));
		}
			
		running	= false;
	
public static voidsetStartDetails(AzureusCore _core)
When AZ is started directly (i.e. not via a plugin) this method is called so that the running state is correctly understood

param
type

		azureus_core	= _core;
		
		running			= true;
	
public static PluginManagerstartAzureus(int ui_type, java.util.Properties properties)

		try{
			class_mon.enter();
			
			if ( running ){
				
				throw( new RuntimeException( "Azureus is already running"));
			}
			
			running	= true;
			
		}finally{
			
			class_mon.exit();
		}
		
			// there's a small window here when an immediate "stop" wouldn't work coz
			// this code would carry on after the stop and start. However, can't easily
			// fix this here...
		
		if ( ui_type == PluginManager.UI_NONE ){
		
				// can't invoke directly as the ui.common stuff isn't part of the core distribution
				// org.gudy.azureus2.ui.common.Main.main( new String[]{"--ui=console"});
			
			try{
				
				azureus_core = AzureusCoreFactory.create();
				
				azureus_core.start();
				
			}catch( Throwable e ){
				
				Debug.printStackTrace( e );
				
					// some idiot (me) forgot to add the exception to the i/f and now we
					// can't add it as is stuffs existing plugins...
				
				throw( new RuntimeException( "Azureus failed to start", e ));
			}
		}else if ( ui_type == PluginManager.UI_SWT ){
				
			if ( properties != null ){
				
				String	mi = (String)properties.get( PluginManager.PR_MULTI_INSTANCE );
				
				if ( mi != null && mi.equalsIgnoreCase("true")){
					
					System.setProperty( org.gudy.azureus2.ui.swt.Main.PR_MULTI_INSTANCE, "true" );
				}
			}
			
			org.gudy.azureus2.ui.swt.Main.main(new String[0]);
		}
		
		if ( azureus_core == null ){
			
			throw( new RuntimeException( "Azureus core failed to initialise" ));
		}
		
		return( azureus_core.getPluginManager());
	
public static voidstopAzureus()

		try{
			class_mon.enter();
		
			if ( !running ){
				
				throw( new RuntimeException( "Azureus is not running"));
			}
						
			try{
				azureus_core.requestStop();
				
			}catch( Throwable e ){
								
				throw( new PluginException( "PluginManager: Azureus close action failed", e));
			}
	
			running	= false;
			
		}finally{
			
			class_mon.exit();
		}