blob: d50458b9818111119f246de0f54017c329016717 [file] [log] [blame]
Pavlin Radoslavovde4c3892014-07-06 23:19:59 -07001package net.onrc.onos.apps.websocket;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.HashMap;
6import java.util.List;
7import java.util.Map;
8
9import net.floodlightcontroller.core.module.FloodlightModuleContext;
10import net.floodlightcontroller.core.module.FloodlightModuleException;
11import net.floodlightcontroller.core.module.IFloodlightModule;
12import net.floodlightcontroller.core.module.IFloodlightService;
13import net.onrc.onos.core.topology.ITopologyService;
14
15/**
16 * The WebSocket module class.
17 */
18public 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}