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

时间:2024-03-06 14:43:18

//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

}

}

}

}