「连载」边缘计算(二十三)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 map[string]chan 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(), }) } |

未完待续......

相关推荐
鲁邦通物联网10 分钟前
储能系统出海防掉线架构:实现断点续传的边缘计算网关技术实战
边缘计算·数据采集·工业数据采集·边缘网关·边缘计算网关·物联网网关·5g数采
EnCi Zheng15 分钟前
01d-前馈神经网络代码实现 [特殊字符]
人工智能·深度学习·神经网络
阿里云大数据AI技术21 分钟前
登顶WorldArena榜单!阿里云PAI助力中科院自动化所、中科第五纪打造具身世界模型FlowWAM
人工智能
hixiong12323 分钟前
C# TensorRT部署RF-DETR目标检测&分割模型
人工智能·目标检测·计算机视觉·ai·c#
小程故事多_8032 分钟前
[大模型面试系列] 深度解析ReAct框架,大模型Agent的“思考+行动”底层逻辑
人工智能·react.js·面试·职场和发展·智能体
逍遥德34 分钟前
AI时代,计算机专业大学生学习指南
java·javascript·人工智能·学习·ai编程
蝎子莱莱爱打怪39 分钟前
Claude Code 省 Token 小妙招:RTK + Caveman 组合拳
前端·人工智能·后端
tanis_340 分钟前
从 PDF 中精准提取表格、图片与公式:MinerU 结构化元素抽取的 3 种方案
人工智能
sali-tec1 小时前
C# 基于OpenCv的视觉工作流-章63-点廓距离
图像处理·人工智能·opencv·计算机视觉
Maiko Star1 小时前
让 AI 开口说话:Spring AI Alibaba 语音合成(TTS)实战
java·人工智能·spring·springai