net.floodlightcontroller.core.module
Class FloodlightModuleLoader

java.lang.Object
  extended by net.floodlightcontroller.core.module.FloodlightModuleLoader
All Implemented Interfaces:
IFloodlightService, IModuleService

public class FloodlightModuleLoader
extends java.lang.Object
implements IModuleService

Finds all Floodlight modules in the class path and loads/starts them.

Author:
alexreimers

Field Summary
static java.lang.String COMPILED_CONF_FILE
           
static java.lang.String FLOODLIGHT_CONFD
           
static java.lang.String FLOODLIGHT_MODULES_KEY
           
protected  FloodlightModuleContext floodlightModuleContext
           
protected static java.util.Set<java.lang.String> initedSet
           
protected static java.lang.Object lock
           
protected static org.slf4j.Logger logger
           
protected static java.util.Map<java.lang.String,IFloodlightModule> moduleNameMap
           
protected static java.util.Map<IFloodlightModule,java.util.Collection<java.lang.Class<? extends IFloodlightService>>> moduleServiceMap
           
protected static java.util.Map<java.lang.Class<? extends IFloodlightService>,java.util.Collection<IFloodlightModule>> serviceMap
           
protected static java.util.Set<java.lang.String> startedSet
           
 
Constructor Summary
FloodlightModuleLoader()
           
 
Method Summary
protected  void addModule(java.util.Map<java.lang.Class<? extends IFloodlightService>,IFloodlightModule> moduleMap, java.util.Collection<IFloodlightModule> moduleSet, IFloodlightModule module)
          Add a module to the set of modules to load and register its services
protected static void findAllModules(java.util.Collection<java.lang.String> mList)
          Finds all IFloodlightModule(s) in the classpath.
protected  void initModules(java.util.Collection<IFloodlightModule> moduleSet)
          Allocate service implementations and then init all the modules
 IFloodlightModuleContext loadModulesFromConfig(java.lang.String fName)
          Loads the modules from a specified configuration file.
 IFloodlightModuleContext loadModulesFromList(java.util.Collection<java.lang.String> configMods, java.util.Properties prop)
          Loads modules (and their dependencies) specified in the list.
protected  IFloodlightModuleContext loadModulesFromList(java.util.Collection<java.lang.String> configMods, java.util.Properties prop, java.util.Collection<IFloodlightService> ignoreList)
          Loads modules (and their dependencies) specified in the list
protected  void parseConfigParameters(java.util.Properties prop)
          Parses configuration parameters for each module
protected  void startupModules(java.util.Collection<IFloodlightModule> moduleSet)
          Call each loaded module's startup method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.slf4j.Logger logger

serviceMap

protected static java.util.Map<java.lang.Class<? extends IFloodlightService>,java.util.Collection<IFloodlightModule>> serviceMap

moduleServiceMap

protected static java.util.Map<IFloodlightModule,java.util.Collection<java.lang.Class<? extends IFloodlightService>>> moduleServiceMap

moduleNameMap

protected static java.util.Map<java.lang.String,IFloodlightModule> moduleNameMap

lock

protected static java.lang.Object lock

initedSet

protected static java.util.Set<java.lang.String> initedSet

startedSet

protected static java.util.Set<java.lang.String> startedSet

floodlightModuleContext

protected FloodlightModuleContext floodlightModuleContext

COMPILED_CONF_FILE

public static final java.lang.String COMPILED_CONF_FILE
See Also:
Constant Field Values

FLOODLIGHT_MODULES_KEY

public static final java.lang.String FLOODLIGHT_MODULES_KEY
See Also:
Constant Field Values

FLOODLIGHT_CONFD

public static final java.lang.String FLOODLIGHT_CONFD
See Also:
Constant Field Values
Constructor Detail

FloodlightModuleLoader

public FloodlightModuleLoader()
Method Detail

findAllModules

protected static void findAllModules(java.util.Collection<java.lang.String> mList)
                              throws FloodlightModuleException
Finds all IFloodlightModule(s) in the classpath. It creates 3 Maps. serviceMap -> Maps a service to a module moduleServiceMap -> Maps a module to all the services it provides moduleNameMap -> Maps the string name to the module

Throws:
FloodlightModuleException - If two modules are specified in the configuration that provide the same service.

loadModulesFromConfig

public IFloodlightModuleContext loadModulesFromConfig(java.lang.String fName)
                                               throws FloodlightModuleException
Loads the modules from a specified configuration file.

Parameters:
fName - The configuration file path
Returns:
An IFloodlightModuleContext with all the modules to be started
Throws:
FloodlightModuleException

loadModulesFromList

protected IFloodlightModuleContext loadModulesFromList(java.util.Collection<java.lang.String> configMods,
                                                       java.util.Properties prop,
                                                       java.util.Collection<IFloodlightService> ignoreList)
                                                throws FloodlightModuleException
Loads modules (and their dependencies) specified in the list

Parameters:
mList - The array of fully qualified module names
ignoreList - The list of Floodlight services NOT to load modules for. Used for unit testing.
Returns:
The ModuleContext containing all the loaded modules
Throws:
FloodlightModuleException

loadModulesFromList

public IFloodlightModuleContext loadModulesFromList(java.util.Collection<java.lang.String> configMods,
                                                    java.util.Properties prop)
                                             throws FloodlightModuleException
Description copied from interface: IModuleService
Loads modules (and their dependencies) specified in the list.

Specified by:
loadModulesFromList in interface IModuleService
Parameters:
configMods - The collection of fully qualified module names to load.
prop - The list of properties that are configuration options.
Returns:
The ModuleContext containing all the loaded modules.
Throws:
FloodlightModuleException

addModule

protected void addModule(java.util.Map<java.lang.Class<? extends IFloodlightService>,IFloodlightModule> moduleMap,
                         java.util.Collection<IFloodlightModule> moduleSet,
                         IFloodlightModule module)
Add a module to the set of modules to load and register its services

Parameters:
moduleMap - the module map
moduleSet - the module set
module - the module to add

initModules

protected void initModules(java.util.Collection<IFloodlightModule> moduleSet)
                    throws FloodlightModuleException
Allocate service implementations and then init all the modules

Parameters:
moduleSet - The set of modules to call their init function on
Throws:
FloodlightModuleException - If a module can not properly be loaded

startupModules

protected void startupModules(java.util.Collection<IFloodlightModule> moduleSet)
                       throws FloodlightModuleException
Call each loaded module's startup method

Parameters:
moduleSet - the module set to start up
Throws:
FloodlightModuleException

parseConfigParameters

protected void parseConfigParameters(java.util.Properties prop)
Parses configuration parameters for each module

Parameters:
prop - The properties file to use