floodlight java_Floodlight-Main.java 分析
Floodlight 的 Main 解析图
需要理解的概念
模块(Module)
Module 是指继承了 IFloodlightModule 接口的类
IFloodlightModule的相关注释
Defines an interface for loadable Floodlight modules.
At a high level, these functions are called in the following order:
getModuleServices() : 获得模块实现的服务列表
getServiceImpls(); 实例化并返回:服务实现类-实现此服务的对象 映射
getModuleDependencies() : 获得模块依赖的列表
init() : internal initializations (don't touch other modules)
startUp() : external initializations (do touch other modules)
所有可加载的模块都有这几种方法,在接下来的加载模块时需要使用到。
每个具体的模块都会重写这几个函数,下面举个 FloodlightProvider 的例子。
getModuleServices()
@Override
public Collection> getModuleServices() {
Collection> services =
new ArrayList>(1);
services.add(IFloodlightProviderService.class);
return services;
}
获得 FloodlightProvider 的服务 IFloodlightProviderService
getServiceImple()
@Override
public Map,
IFloodlightService> getServiceImpls() {
controller = new Controller();
Map,
IFloodlightService> m =
new HashMap,
IFloodlightService>();
m.put(IFloodlightProviderService.class, controller);
return m;
}
返回服务实现类和实现用的对象的Map。
getModuleDependencies()
@Override
public Collection> getModuleDependencies() {
Collection> dependencies =
new ArrayList>(4);
dependencies.add(IStorageSourceService.class);
dependencies.add(IPktInProcessingTimeService.class);
dependencies.add(IRestApiService.class);
dependencies.add(IDebugCounterService.class);
dependencies.add(IOFSwitchService.class);
dependencies.add(IThreadPoolService.class);
dependencies.add(ISyncService.class);
return dependencies;
}
返回依赖的列表
其他
init(),startup(),到对应的模块去看就可以了。
有的模块是没有服务依赖的,比如 ThreadPool模块。
服务(Service)
Service 是指继承了 IFloodlightService 接口的类。
public abstract interface IFloodlightService {
// This space is intentionally left blank....don't touch it
}
模块使用getModuleServices()方法可以获得对应的服务列表,可以到源码去看对应的服务功能。
Main函数
解析命令行参数
加载模块
启动 REST 服务器
启动 Controller
命令行参数解析
CmdLineSetting 定义了命令行参数的格式
public static final String DEFAULT_CONFIG_FILE = "src/main/resources/floodlightdefault.properties";
@Option(name="-cf", aliases="--configFile", metaVar="FILE", usage="Floodlight configuration file")
private String configFile = DEFAULT_CONFIG_FILE;
如果没有使用-cf指定配置文件路径,则使用默认路径“src/main/resources/floodlightdefault.properties”
CmdLineParser 解析命令参数
CmdLineParser parser = new CmdLineParser(settings)
parser.parserArgument(args)
加载模块
moduleContext=fml.loadModulesFromConfig(settings.getModuleFile())
settings.getModuleFile()提供配置文件的路径
mergeProperties()
目的是获得配置文件里的模块的集合configMods和prop是除去配置文件里的模块键值对后剩余的配置信息(模块的配置参数)
loadModulesFromList(configsMods,prop)
findAllModule(configMods)
填充moduleNameMap,moduleServiceMap,ServiceMap
这个方法比较重要的是这个 ServiceLoader,返回服务加载器
ServiceLoader moduleLoader =
ServiceLoader.load(IFloodlightModule.class, cl);
ServiceLoader 为了注册服务,需要在类路径 src/main/resources/META_INF/services文件夹内列好注册服务的模块,可以得到继承了 IFloodlightModule 接口的实现类
使用moduleLoader.iterator()迭代器去填充moduleNameMap,moduleServiceMap,ServiceMap
moduleNameMap 模块名称-模块对象 Map
moduleServiceMAP 模块名称-模块服务 Map
ServiceMap 模块服务-模块名称 Map
traverseDeps(moduleName,modsToLoad,moduleList,moduleMap,modsVisited)
addModule()
添加模块到模块的哈希集moduleMap,同时注册它们的服务(即得到已加载模块序列 moduleList)
parseConfigParameters(prop)
解析每个模块的配置参数
取配置文件的一条参数配置net.floodlightcontroller.forwarding.Forwarding.match=in-port, vlan, mac, ip, transport举例
key:net.floodlightcontroller.forwarding.Forwarding.match
String configKey=key.substring(LastPeriod+1)
获到的就是 match,即 configKey=match
String systemKey = System.getProperty(key);
if (systemKey != null) {
configValue = systemKey;
} else {
configValue = prop.getProperty(key);
}
如果系统属性已经存在,则使用系统属性的值,如果不存在,则configValue = prop.getProperty(key);【即 configValue 在此处为in-port, vlan, mac, ip, transport】
floodlightModuleContext.addConfigParam(mod,configKey,configValue)
添加模块的配置参数
FloodlightModuleLoader 类下的方法
public void addConfigParam(IFloodlightModule mod, String key, String value) {
Map moduleParams = configParams.get(mod.getClass());
if (moduleParams == null) {
moduleParams = new HashMap();
configParams.put(mod.getClass(), moduleParams);
}
moduleParams.put(key, value);
}
initModules(moduleList)
初始化已加载模块列表下的模块
获得模块的服务实例
Map,
IFloodlightService> simpls = module.getServiceImpls();
添加服务到 floodlightModuleContext
if (floodlightModuleContext.getServiceImpl(s.getKey()) == null) {
floodlightModuleContext.addService(s.getKey(),
s.getValue());
遍历已加载模块集,开始初始化模块,调用模块的方法:init
for (IFloodlightModule module : moduleSet) {
// init the module
if (logger.isDebugEnabled()) {
logger.debug("Initializing " +
module.getClass().getCanonicalName());
}
module.init(floodlightModuleContext);
}
startupModules(moduleList)
调用已加载模块的启动方法
遍历已加载模块集,调用每个模块的启动方法
for (IFloodlightModule m : moduleSet) {
if (logger.isDebugEnabled()) {
logger.debug("Starting " + m.getClass().getCanonicalName());
}
m.startUp(floodlightModuleContext);
}
return floodlightModuleContext
返回公共环境变量
fml.runModules()
运动控制器模块和所有模块
getModuleList()
获得一个按初始化顺序的模块列表
返回一个不可修改的已加载模块序列,如果没被初始化则返回 null
public List getModuleList() {
if (loadedModuleList == null)
return Collections.emptyList();
else
return Collections.unmodifiableList(loadedModuleList);
}
runModules()
for (IFloodlightModule m : getModuleList()) {
for (Method method : m.getClass().getDeclaredMethods()) {
Run runAnnotation = method.getAnnotation(Run.class);
if (runAnnotation != null) {
RunMethod runMethod = new RunMethod(m, method);
if(runAnnotation.mainLoop()) {
mainLoopMethods.add(runMethod);
} else {
runMethod.run();
}
}
}
}
for 循环遍历模块中的方法,找到@run注解的方法为主方法,以下的就是 FloodlightProvider 提供的 run 方法
@Run(mainLoop=true)
public void run() throws FloodlightModuleException {
controller.run();
}
运行控制器的模块
mainLoopMethods.get(0).run();
floodlight java_Floodlight-Main.java 分析相关推荐
- Exception in thread main java.lang.IncompatibleClassChangeError: net/sf/cglib/core/DebuggingClassW
问题: 今天在运行程序的时候报如下错误. 1. java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor 2. Exception i ...
- maven项目编译漏掉src/main/java下的xml配置文件
在整合Spring + Mybatis框架的时候,自动扫描配置都已经配置好了. 配置如下: <?xml version="1.0" encoding="UTF-8& ...
- Exception in thread “main“ java.lang.NoClassDefFoundError: org/apache/ibatis/io/Resources
项目场景: 在学习mybatis框架的时候,刚刚学习如果查询数据库user表中的信息时 问题描述: 所有步骤都是按照教程上走的,但是运行后里面就出现了 Exception in thread &quo ...
- floodlight java_floodlight学习系列(1)——在Eclipse中安装运行floodlight
环境:ubuntu 16.04 前提:已经成功安装了JDK和Ecplise 1.安装floodlight apt-get install build-essential default-jdk ant ...
- maven web项目不能创建src/main/java等文件夹的问题
eclipse创建maevn web项目,在选择maven_archetype_webapp原型后,默认只有src/main/resources这个Source Floder. 按照maven目录结 ...
- SparkStreaming Exception in thread main java.lang.IllegalArgumentException xxx is not a valid
Exception in thread "main" java.lang.IllegalArgumentException xxx is not a valid DFS fi ...
- exception in thread main java,【异常】idea执行Main方法出现 Exception in thread main java.lang.NoClassDefFo...
一.异常复现步骤 1)首先得是一个Spring MVC项目 注:Spring Boot项目有内置的web 容器,不会出现该问题 2)main方法存在于使用HttpServletRequest类的类中 ...
- java 分析java死锁_Java死锁示例–如何分析死锁情况
java 分析java死锁 死锁是两个线程或多个线程永远被阻塞的编程情况,这种情况发生在至少两个线程和两个或更多资源的情况下. 在这里,我编写了一个简单的程序,它将导致死锁情况,然后我们将看到如何对其 ...
- java 分析java死锁_有益的CountDownLatch和棘手的Java死锁
java 分析java死锁 您是否曾经使用过java.util.concurrent.CountDownLatch ? 这是在两个或多个线程之间实现同步的非常方便的类,在该类中,一个或多个线程可以等待 ...
最新文章
- vb链接远程mysql数据库代码_vb链接远程mysql数据库代码
- Java 反射修改类的常量值、静态变量值、属性值
- “==”和equals()那些事
- Redis缓存数据库服务器
- nodejs_NodeJS历险记
- 10分钟虚拟设备接入阿里云IoT平台实战
- 基于CSS实现的尖角提示符
- STM32基础分析——USART的DMA模式
- 详解VMware虚拟机中添加新硬盘并挂载的方法
- 传统车载网络,软件定义汽车
- 计算机网络对生活的影响论文,浅论计算机对我们生活的影响论文
- 【STC单片机】通过ADC外部输入调节PWM占空比输出并串口打印当前脉冲值
- js图片压缩工具img-compressor的使用
- Alink漫谈(二十二) :源码分析之聚类评估
- GAC注册/卸载 dll
- 财报前被香港证监会点名,富途内控再受拷问
- IDEA一直在indexing的解决方案
- 数据库基础内容(超级详细)
- 计算机存储单位 KB,MB,GB,TB,PB
- dns服务器未响应网速卡,DNS服务器未响应且网速突然变的不好是什么原因 怎样解决...
热门文章
- 数学与计算机学院英文翻译,数学与计算机科学逻辑,logic for matheamtics and computer science,音标,读音,翻译,英文例句,英语词典...
- lwy梦境中的斐波那契数列——诈骗签到题
- OpenMLDB Meetup No.6 回顾 | OpenMLDB+37 手游:一键查收特征计算场景案例及进阶使用攻略
- 常见机器学习算法大纲
- (附源码)基于Android社区生鲜O2O订购系统设计与实现 毕业设计231443
- 狼羊菜问题的算法思想和C++实现(二进制状态表示 递归状态转移 回溯 剪枝)
- html基础图片img
- Java 工具包 Jodd
- 小技巧,把Markdown文本发布到微信公众号文章
- C++运算符重载详解