Pavlin Radoslavov | de4c389 | 2014-07-06 23:19:59 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.websocket; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.HashMap; |
| 6 | import java.util.List; |
| 7 | import java.util.Map; |
| 8 | |
| 9 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 10 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 11 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 13 | import net.onrc.onos.core.topology.ITopologyService; |
| 14 | |
| 15 | /** |
| 16 | * The WebSocket module class. |
| 17 | */ |
| 18 | public class WebSocketModule implements IFloodlightModule, IWebSocketService { |
| 19 | private WebSocketManager webSocketManager; |
| 20 | private static final int DEFAULT_WEBSOCKET_PORT = 8081; |
| 21 | |
| 22 | @Override |
| 23 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 24 | List<Class<? extends IFloodlightService>> services = |
| 25 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 26 | services.add(IWebSocketService.class); |
| 27 | return services; |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 32 | getServiceImpls() { |
| 33 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = |
| 34 | new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(); |
| 35 | impls.put(IWebSocketService.class, this); |
| 36 | return impls; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 41 | List<Class<? extends IFloodlightService>> dependencies = |
| 42 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 43 | dependencies.add(ITopologyService.class); |
| 44 | return dependencies; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void init(FloodlightModuleContext context) |
| 49 | throws FloodlightModuleException { |
| 50 | ITopologyService topologyService = |
| 51 | context.getServiceImpl(ITopologyService.class); |
| 52 | |
| 53 | // |
| 54 | // Read the configuration options |
| 55 | // |
| 56 | int webSocketPort = DEFAULT_WEBSOCKET_PORT; |
| 57 | Map<String, String> configOptions = context.getConfigParams(this); |
| 58 | String port = configOptions.get("port"); |
| 59 | if (port != null) { |
| 60 | webSocketPort = Integer.parseInt(port); |
| 61 | } |
| 62 | |
| 63 | // Initialize the WebSocketManager |
| 64 | webSocketManager = new WebSocketManager(topologyService, |
| 65 | webSocketPort); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void startUp(FloodlightModuleContext context) { |
| 70 | webSocketManager.startup(); |
| 71 | } |
| 72 | } |