「连载」边缘计算(二十四)03-04:边缘部分源码(源码分析篇)

(接上篇)

在Register()函数中对EdgeHub struct的初始化只是对EdgeHub struct中的controller进行初始化。controller的初始化函数具体如下所示。

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edgehub/controller.go |
| //NewEdgeHubController creates and returns a EdgeHubController object func NewEdgeHubController() *Controller { return &Controller{ config: &config.GetConfig().CtrConfig, stopChan: make(chan struct{}), syncKeeper: make(map[string]chan model.Message), } } |

NewEdgeHubController()函数中嵌套了一个获取配置信息的函数调用,具体如下所示。

|----------------------------------------|
| config: &config.GetConfig().CtrConfig |

config.GetConfig()函数定义具体如下所示。

|------------------------------------------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edgehub/config/config.go |
| var edgeHubConfig EdgeHubConfig ... //GetConfig returns the EdgeHub configuration object func GetConfig() *EdgeHubConfig { return &edgeHubConfig } |

GetConfig()函数只返回了&edgeHubConfig,而edgeHubConfig是一个EdgeHubConfig struct类型的全局变量。至于该变量是在哪里被赋值,怎么赋值的,暂且留个疑问------* EdgeHubConfig赋值疑问。

到此,EdgeHub struct的初始化就告一段落了。下面分析EdgeHub的启动函数,具体如下所示。

|-----------------------------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edgehub/module.go |
| //Start sets context and starts the controller func (eh *EdgeHub) Start(c *context.Context) { eh.context = c eh.controller.Start(c) } |

EdgeHub启动函数Start()只做了两件事。

  1. 接收并存储传入的消息管道;
  2. 启动EdgeHub的controller。

由前面的分析可知,EdgeHub的controller作为EdgeHub功能的主要载体。其启动函数囊括EdgeHub绝大部分启动逻辑。继续进入controller的启动函数,具体如下所示。

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edgehub/controller.go |
| //Start will start EdgeHub func (ehc *Controller) Start(ctx *context.Context) { config.InitEdgehubConfig() for { err := ehc.initial(ctx) ... err = ehc.chClient.Init() ... // execute hook func after connect ehc.pubConnectInfo(true) go ehc.routeToEdge() go ehc.routeToCloud() go ehc.keepalive() // wait the stop singal // stop authinfo manager/websocket connection <-ehc.stopChan ehc.chClient.Uninit() // execute hook fun after disconnect ehc.pubConnectInfo(false) // sleep one period of heartbeat, then try to connect cloud hub again time.Sleep(ehc.config.HeartbeatPeriod * 2) // clean channel clean: for { select { case <-ehc.stopChan: default: break clean } } } } |

从Controller的启动函数Start()的定义,可以清楚地看到其包含了EdgehubConfig初始化、各种业务go routine的启动和最后的退出清理。下面逐个深入剖析。

未完待续......

相关推荐
OpenBayes8 分钟前
教程上新|DeepSeek-OCR 2公式/表格解析同步改善,以低视觉token成本实现近4%的性能跃迁
人工智能·深度学习·目标检测·机器学习·大模型·ocr·gpu算力
冰糖猕猴桃43 分钟前
【AI】把“大杂烩抽取”拆成多步推理:一个从单提示到多阶段管线的实践案例
大数据·人工智能·ai·提示词·多步推理
PPIO派欧云44 分钟前
PPIO上线GLM-OCR:0.9B参数SOTA性能,支持一键部署
人工智能·ai·大模型·ocr·智谱
雨大王5121 小时前
怎么打造一个能自我进化的制造数字基座?
人工智能·汽车·制造
fengfuyao9851 小时前
基于MATLAB的表面织构油润滑轴承故障频率提取(改进VMD算法)
人工智能·算法·matlab
爱吃泡芙的小白白1 小时前
深入解析CNN中的Dropout层:从基础原理到最新变体实战
人工智能·神经网络·cnn·dropout·防止过拟合
Eloudy1 小时前
全文 -- TileLang: A Composable Tiled Programming Model for AISystems
人工智能·量子计算·arch
才盛智能科技2 小时前
K链通×才盛云:自助KTV品牌从0到1孵化超简单
大数据·人工智能·物联网·自助ktv系统·才盛云
广州赛远2 小时前
IRB2600-201.65特殊机器人防护服清洗工具详解与避坑指南
大数据·人工智能
Eloudy2 小时前
直接法 读书笔记 01 第1章 引言
人工智能·机器学习·hpc