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

Method cleanupActor

pkg/actor/system.go:653–691  ·  view source on GitHub ↗

cleanupActor 清理 Actor

(cell *actorCell)

Source from the content-addressed store, hash-verified

651
652// cleanupActor 清理 Actor
653func (s *System) cleanupActor(cell *actorCell) {
654 cell.stateMu.Lock()
655 cell.state = actorStateStopped
656 cell.stateMu.Unlock()
657
658 // 发送 Stopped 消息
659 ctx := &Context{Self: cell.pid, system: s, ctx: context.Background()}
660 cell.actor.Receive(ctx, &Stopped{})
661
662 // 通知所有监控者
663 for _, watcher := range cell.watchers {
664 s.Send(watcher, &Terminated{Who: cell.pid})
665 }
666
667 // 停止所有子 Actor
668 for _, child := range cell.children {
669 s.Stop(child)
670 }
671
672 // 从注册表中移除
673 s.actorsMu.Lock()
674 delete(s.actors, cell.pid.ID)
675 s.actorsMu.Unlock()
676
677 // 从父 Actor 中移除
678 if cell.parent != nil {
679 s.actorsMu.RLock()
680 if parentCell, ok := s.actors[cell.parent.ID]; ok {
681 delete(parentCell.children, cell.pid.ID)
682 }
683 s.actorsMu.RUnlock()
684 }
685
686 // 取消上下文
687 cell.cancel()
688
689 atomic.AddInt64(&s.stats.TotalActors, -1)
690 actorLog.Debug(context.Background(), "actor stopped", map[string]any{"actor_id": cell.pid.ID})
691}
692
693// getChildrenPIDs 获取子 Actor PID 列表
694func (s *System) getChildrenPIDs(cell *actorCell) []*PID {

Callers 1

actorLoopMethod · 0.95

Calls 6

SendMethod · 0.95
StopMethod · 0.95
deleteFunction · 0.85
ReceiveMethod · 0.65
DebugMethod · 0.65
cancelMethod · 0.45

Tested by

no test coverage detected