我從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()中實現殺死該進程。 任何人都可以幫助我嗎?