Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.core; |
| 2 | |
| 3 | import org.kohsuke.args4j.CmdLineException; |
| 4 | import org.kohsuke.args4j.CmdLineParser; |
| 5 | |
| 6 | import net.floodlightcontroller.core.internal.CmdLineSettings; |
| 7 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 8 | import net.floodlightcontroller.core.module.FloodlightModuleLoader; |
| 9 | import net.floodlightcontroller.core.module.IFloodlightModuleContext; |
| 10 | import net.floodlightcontroller.restserver.IRestApiService; |
| 11 | |
| 12 | /** |
| 13 | * Host for the Floodlight main method |
| 14 | * @author alexreimers |
| 15 | */ |
| 16 | public class Main { |
| 17 | |
| 18 | /** |
| 19 | * Main method to load configuration and modules |
| 20 | * @param args |
| 21 | * @throws FloodlightModuleException |
| 22 | */ |
| 23 | public static void main(String[] args) throws FloodlightModuleException { |
| 24 | // Setup logger |
| 25 | System.setProperty("org.restlet.engine.loggerFacadeClass", |
| 26 | "org.restlet.ext.slf4j.Slf4jLoggerFacade"); |
| 27 | |
| 28 | CmdLineSettings settings = new CmdLineSettings(); |
| 29 | CmdLineParser parser = new CmdLineParser(settings); |
| 30 | try { |
| 31 | parser.parseArgument(args); |
| 32 | } catch (CmdLineException e) { |
| 33 | parser.printUsage(System.out); |
| 34 | System.exit(1); |
| 35 | } |
| 36 | |
| 37 | // Load modules |
| 38 | FloodlightModuleLoader fml = new FloodlightModuleLoader(); |
| 39 | IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(settings.getModuleFile()); |
| 40 | // Run REST server |
| 41 | IRestApiService restApi = moduleContext.getServiceImpl(IRestApiService.class); |
| 42 | restApi.run(); |
| 43 | // Run the main floodlight module |
| 44 | IFloodlightProviderService controller = |
| 45 | moduleContext.getServiceImpl(IFloodlightProviderService.class); |
| 46 | // This call blocks, it has to be the last line in the main |
| 47 | controller.run(); |
| 48 | } |
| 49 | } |