MCPcopy Create free account
hub / github.com/astercloud/aster / Receive

Method Receive

pkg/actor/supervisor.go:356–381  ·  view source on GitHub ↗

Receive 处理消息

(ctx *Context, msg Message)

Source from the content-addressed store, hash-verified

354
355// Receive 处理消息
356func (s *SupervisorActor) Receive(ctx *Context, msg Message) {
357 switch m := msg.(type) {
358 case *Started:
359 // 启动所有子 Actor
360 for _, spec := range s.config.Children {
361 child := spec.Factory()
362 props := spec.Props
363 if props == nil {
364 props = DefaultProps(spec.Name)
365 }
366 props.SupervisorStrategy = s.config.Strategy
367 pid := ctx.SpawnWithProps(child, props)
368 s.children[spec.Name] = pid
369 }
370
371 case *Terminated:
372 // 子 Actor 终止,根据策略处理
373 delete(s.children, m.Who.ID)
374
375 case *Stopping:
376 // 停止所有子 Actor
377 for _, pid := range s.children {
378 ctx.Stop(pid)
379 }
380 }
381}
382
383// GetChild 获取子 Actor
384func (s *SupervisorActor) GetChild(name string) *PID {

Callers

nothing calls this directly

Calls 4

DefaultPropsFunction · 0.85
deleteFunction · 0.85
StopMethod · 0.65
SpawnWithPropsMethod · 0.45

Tested by

no test coverage detected