「连载」边缘计算(二十三)02-28:边缘部分源码(源码分析篇)

(接上篇)

EdgeCore 之 edgehub

前面对EdgeCore组件的edged、devicetwin功能模块进行了分析,本节对EdgeCore组件的另一个功能模块edgehub进行剖析。 edgehub作为edge部分与cloud部分进行交互的门户,我们有必要将edgehub相关内容彻底分析清楚,为使用过程中的故障排查和未来的功能扩展与性能优化提供便利。edgehub的剖析具体包括edgehub的struct调用链剖析、edgehub的具体逻辑剖析。

edgehub 的struct组成剖析

EdgeCore模块注册函数具体如下所示。

|-----------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/cmd/EdgeCore/app/server.go |
| // registerModules register all the modules started in EdgeCore func registerModules() { ... edgehub.Register() ... } |

registerModules()函数中的edgehub.Register()具体如下所示。

|------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edgehub/module.go |
| // Register register edgehub func Register() { core.Register(&EdgeHub{ controller: NewEdgeHubController(), }) } |

顺着Register()函数中EdgeHub struct的实例化语句进入EdgeHub struct定义,具体如下所示。

|----------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edgehub/module.go |
| //EdgeHub defines edgehub object structure type EdgeHub struct { context *context.Context controller *Controller } |

EdgeHub struct中包含*context.Context和*Controller 两个属性。

1) *context.Context: 在《深入理解边缘计算:云、边、端工作原理与源码分析》8.3.2中,笔者已经分析过*context.Context,它是一个基于go-channels的消息框架,EdgeCore用它作为各功能模块之间通信的消息管道。

2)*Controller:edgehub的主要功能载体。

Controller struct的定义具体如下所示。

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edgehub/controller.go |
| //Controller is EdgeHub controller object type Controller struct { context *context.Context chClient clients.Adapter config *config.ControllerConfig stopChan chan struct{} syncKeeper mapstringchan model.Message keeperLock sync.RWMutex } |

从Controller struct的定义可以确定,Controller struct是edgehub核心功能载体没错了。

到此,edgehub的struct组成剖析就结束了。接下来剖析edgehub的具体逻辑。

edgehub 的具体逻辑剖析

回到edgehub的注册函数,开始剖析edgehub相关的逻辑,具体如下所示。

|------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edgehub/module.go |
| // Register register edgehub func Register() { core.Register(&EdgeHub{ controller: NewEdgeHubController(), }) } |

「 未完待续...... 」

相关推荐
胡家伟++15 小时前
一片叶子的赋役与风流——茶政·茶课·茶税·茶诗茶画
人工智能·aigc·ai搜索
198******1263415 小时前
深度解读Work Agent长程任务执行的底层运行逻辑
人工智能
秦先生在广东15 小时前
n8n 深度解析:AI 原生的混合编程自动化平台
人工智能
feasibility.15 小时前
AI 解牛:刀刃不再需要手——技艺、判断与一次学习机制的重构
人工智能·职场发展·具身智能·skill·道·术
大嘴皮猴儿15 小时前
为跨境电商卖家分析目前AI跨境翻译网站哪个好
大数据·人工智能·教育电商·ai图片翻译工具哪个好·ai图片翻译软件免费
秦先生在广东15 小时前
《科技爱好者周刊》内容全景:从AI机制到开源协作的200期观察
人工智能
小宋102115 小时前
Agent Skills 从零实战:SKILL.md、渐进式加载、测试与版本治理
大数据·网络·人工智能
释厄62315 小时前
BSD 基础论——不要忘记连接·不要停滞循环·AI基础算法
人工智能·算法
悟天特斯15 小时前
楼宇自控的“最后一公里“:从设备控制到数据驱动的建筑智能体
人工智能·物联网
程序猿阿森15 小时前
FastText 全面解析:从文本张量表示到文本分类实战
人工智能·分类·数据挖掘