我从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()中实现杀死该进程。 任何人都可以帮助我吗?