2013-03-19 119 views
0

我从mavenized floodlight创建了一个OSGi包。我使用blueprint config.xml来激活这个包。下面是蓝图config.xml文件:如何停止运行Floodlight实例?

<bean id="flbean" 
    class="net.floodlightcontroller.core.FloodlightBean" 
    init-method="init" destroy-method="destroy"> 
</bean> 

我创建了一个类FloodlightBean提供init()和stop()方法来启动和停止包:

public class FloodlightBean { 

public void init() throws FloodlightModuleException { 
    System.out.println("start floodlight"); 
    // Setup logger 
    System.setProperty("org.restlet.engine.loggerFacadeClass", 
      "org.restlet.ext.slf4j.Slf4jLoggerFacade"); 

    CmdLineSettings settings = new CmdLineSettings(); 
    /*CmdLineParser parser = new CmdLineParser(settings); 
    try { 
     parser.parseArgument(args); 
    } catch (CmdLineException e) { 
     parser.printUsage(System.out); 
     System.exit(1); 
    }*/ 

    // Load modules 
    FloodlightModuleLoader fml = new FloodlightModuleLoader(); 
    IFloodlightModuleContext moduleContext = fml 
      .loadModulesFromConfig(settings.getModuleFile()); 
    // Run REST server 
    IRestApiService restApi = moduleContext 
      .getServiceImpl(IRestApiService.class); 
    restApi.run(); 
    // Run the main floodlight module 
    IFloodlightProviderService controller = moduleContext 
      .getServiceImpl(IFloodlightProviderService.class); 
    // This call blocks, it has to be the last line in the main 
    controller.run(); 
} 

public void destroy() { 

    System.out.println("stop floodlight"); 
} 

}

对于init()方法,我只是将net.floodlightcontroller.core.Main中的代码复制到它中。现在Floodlight可以在OSGi容器中启动。但问题是,一旦泛光灯开始使用,它将永远运行。我不知道如何实施destroy()来停止泛光灯。

我只是发现泛光灯是多线程的。所以我不能仅仅为net.floodlightcontroller.core.Main中的代码创建一个线程。 我想知道是否可以为init()创建一个进程,并在destroy()中实现杀死该进程。 任何人都可以帮助我吗?

回答

0

如果IFloodlightModuleLoader或Context没有停止/停用/关闭方法来停止那些你被正式使用的线程。非正式地,您可以在调用run之前创建一个ThreadGroup。如果你幸运的话,你可以调用setDaemon(true),这可能有助于杀死线程,如果他们是唯一使用虚拟机的线程。否则,你可以在ThreadGroup上调用stop()。这可能会起作用,但因为它不安全而被弃用。