String id,
String name )
throws Throwable
{
PluginManager plug_man = AzureusCoreFactory.getSingleton().getPluginManager();
PluginInterface pi = plug_man.getPluginInterfaceByID( id, false );
if ( pi == null ){
listener.updateActivity( "Installing " + name );
final AESemaphore sem = new AESemaphore( "analyserWait" );
synchronized( StreamManager.this ){
if ( cancelled ){
throw( new Exception( "Cancelled" ));
}
active_sem = sem;
}
final Throwable[] error = { null };
new SimplePluginInstaller(
id,
"dlg.install." + id,
new UIFunctions.actionListener()
{
public void
actionComplete(
Object result )
{
try{
if ( result instanceof Boolean ){
}else{
error[0] = (Throwable)result;
}
}finally{
sem.release();
}
}
});
sem.reserve();
synchronized( StreamManager.this ){
if ( cancelled ){
throw( new Exception( "Cancelled" ));
}
active_sem = null;
}
if( error[0] != null ){
throw( error[0] );
}
long start = SystemTime.getMonotonousTime();
listener.updateActivity( "Waiting for plugin initialisation" );
while( true ){
if ( cancelled ){
throw( new Exception( "Cancelled" ));
}
if ( SystemTime.getMonotonousTime() - start >= 30*1000 ){
throw( new Exception( "Timeout waiting for " + name + " to initialise" ));
}
pi = plug_man.getPluginInterfaceByID( id, false );
if ( pi != null && pi.getPluginState().isOperational()){
return( pi );
}