「连载」边缘计算(二十四)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的启动和最后的退出清理。下面逐个深入剖析。

未完待续......

相关推荐
chenkangck5029 分钟前
AI大模型之旅--milvus向量库安装
人工智能·aigc·milvus
学习前端的小z31 分钟前
【AI视频】Runway:Gen-2 图文生视频与运动模式详解
人工智能·aigc·音视频
SpikeKing2 小时前
LLM - 理解 多模态大语言模型(MLLM) 的 指令微调(Instruction-Tuning) 与相关技术 (四)
人工智能·语言模型·指令微调·数据调整·自指令·数据混合·instruction
开MINI的工科男3 小时前
【笔记】自动驾驶预测与决策规划_Part3_路径与轨迹规划
人工智能·笔记·自动驾驶·预测与决策
xuanyu226 小时前
Linux常用指令
linux·运维·人工智能
凡人的AI工具箱6 小时前
AI教你学Python 第11天 : 局部变量与全局变量
开发语言·人工智能·后端·python
晓星航6 小时前
Docker本地部署Chatbot Ollama搭建AI聊天机器人并实现远程交互
人工智能·docker·机器人
Kenneth風车6 小时前
【机器学习(五)】分类和回归任务-AdaBoost算法-Sentosa_DSML社区版
人工智能·算法·低代码·机器学习·数据分析
AI小白龙*6 小时前
大模型团队招人(校招):阿里巴巴智能信息,2025届春招来了!
人工智能·langchain·大模型·llm·transformer
空指针异常Null_Point_Ex7 小时前
大模型LLM之SpringAI:Web+AI(一)
人工智能·chatgpt·nlp