| 94 | |
| 95 | (6/13): |
| 96 | [[BR]] |
| 97 | [[BR]] |
| 98 | A (not-so) quick revisit of the module loading system in Floodlight was done to figure out how exactly a module learns to subscribe to the main controller module. |
| 99 | |
| 100 | Starting at the top, in the ''init()'' function of each module is almost always this line: |
| 101 | {{{ |
| 102 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 103 | }}} |
| 104 | Where ''context'' is an instance of `FloodlightModuleContext`, which contains a mapping between the interfaces and the services providing them. ''getServiceImpl()'', in the case above, returns the service providing the IFloodlightProviderService interface, which is the core controller. |
| 105 | |
| 106 | `FloodlightModuleLoader` is the actual class responsible for populating `FloodlightModuleContext`'s mapping; Recalling, from Main.java: |
| 107 | {{{ |
| 108 | FloodlightModuleLoader fml = new FloodlightModuleLoader(); |
| 109 | IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(settings.getModuleFile()); |
| 110 | }}} |
| 111 | Internally, for each module exporting a service, in ''initModules()'' `FloodlightModuleLoader` calls ''getServiceImpls()'', an `IFloodlightModule` function that lets modules define the services that they export. It then uses `FloodlightModuleContext`'s ''addService()'' in order to fill its mapping. |
| 112 | |
| 113 | Returning to the controller mapped to ''IFloodlightProviderService.class'', we see that it is a service exported by the module `FloodlightProvider`. It is the first module to be loaded by the module loading system, and therefore the mapping to the controller is there for the rest of the modules to register with. |
| 114 | |
| 115 | This leads us to a potential way to place a module between the controller and the rest of the modules: |
| 116 | * Re-name the real IFloodlightProviderService to something else |
| 117 | * Implement a module that subscribes to the re-named controller service |
| 118 | * Implement a FVController from IFloodlightProviderService |
| 119 | * export this as a service with key IFloodlightProviderService.class |
| 120 | |
| 121 | This shouldn't require any change on the other modules (except the FloodlightProvider). |