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

未完待续......

相关推荐
南方者10 小时前
重磅升级!文心 ERNIE-5.0 新一代原生全模态大模型,这你都不认可它吗?!
人工智能·aigc
庄周迷蝴蝶10 小时前
旋转位置编码(Rotary Position Embedding,RoPE)
人工智能·机器学习
xier_ran10 小时前
深度学习:RMSprop 优化算法详解
人工智能·深度学习·算法
大千AI助手10 小时前
Prefix-Tuning:大语言模型的高效微调新范式
人工智能·神经网络·自然语言处理·llm·prefix-tuning·大千ai助手·前缀微调
雾江流10 小时前
RikkaHub 1.6.11 | 开源的本地大型语言模型聚合应用,支持多种AI服务提供商
人工智能·语言模型·自然语言处理·软件工程
Mr_Dwj11 小时前
【Python】Python 基本概念
开发语言·人工智能·python·大模型·编程语言
私人珍藏库11 小时前
AI一键PPT 2.0.3 一键智能生成
人工智能·powerpoint
com_4sapi12 小时前
2025 权威认证头部矩阵系统全景对比发布 双榜单交叉验证
大数据·c语言·人工智能·算法·矩阵·机器人
2401_8414956412 小时前
【自然语言处理】基于规则基句子边界检测算法
人工智能·python·自然语言处理·规则·文本·语言·句子边界检测算法
科技云报道12 小时前
AI+云计算互融共生,2025AI云产业发展大会即将举行
人工智能·云计算