Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.jython; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | import java.util.HashMap; |
| 5 | import java.util.Map; |
| 6 | |
| 7 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; |
| 9 | |
| 10 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 11 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 13 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 14 | |
| 15 | public class JythonDebugInterface implements IFloodlightModule { |
| 16 | protected static Logger log = LoggerFactory.getLogger(JythonDebugInterface.class); |
| 17 | protected JythonServer debug_server; |
| 18 | protected static int JYTHON_PORT = 6655; |
| 19 | |
| 20 | @Override |
| 21 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 22 | // We don't export services |
| 23 | return null; |
| 24 | } |
| 25 | |
| 26 | @Override |
| 27 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 28 | getServiceImpls() { |
| 29 | // We don't export services |
| 30 | return null; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public Collection<Class<? extends IFloodlightService>> |
| 35 | getModuleDependencies() { |
| 36 | // We don't have any dependencies |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void init(FloodlightModuleContext context) |
| 42 | throws FloodlightModuleException { |
| 43 | // no-op |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public void startUp(FloodlightModuleContext context) { |
| 48 | Map<String, Object> locals = new HashMap<String, Object>(); |
| 49 | // add all existing module references to the debug server |
| 50 | for (Class<? extends IFloodlightService> s : context.getAllServices()) { |
| 51 | // Put only the last part of the name |
| 52 | String[] bits = s.getCanonicalName().split("\\."); |
| 53 | String name = bits[bits.length-1]; |
| 54 | locals.put(name, context.getServiceImpl(s)); |
| 55 | } |
| 56 | |
| 57 | // read our config options |
| 58 | Map<String, String> configOptions = context.getConfigParams(this); |
| 59 | int port = JYTHON_PORT; |
| 60 | String portNum = configOptions.get("port"); |
| 61 | if (portNum != null) { |
| 62 | port = Integer.parseInt(portNum); |
| 63 | } |
| 64 | |
| 65 | JythonServer debug_server = new JythonServer(port, locals); |
| 66 | debug_server.start(); |
| 67 | } |
| 68 | } |