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

Method applyDirective

pkg/actor/system.go:569–604  ·  view source on GitHub ↗

applyDirective 应用监督指令

(cell *actorCell, directive Directive)

Source from the content-addressed store, hash-verified

567
568// applyDirective 应用监督指令
569func (s *System) applyDirective(cell *actorCell, directive Directive) {
570 switch directive {
571 case DirectiveResume:
572 // 继续运行,不做处理
573 actorLog.Info(context.Background(), "actor resumed after failure", map[string]any{"actor_id": cell.pid.ID})
574
575 case DirectiveRestart:
576 cell.restarts++
577 cell.stateMu.Lock()
578 cell.state = actorStateRestarting
579 cell.stateMu.Unlock()
580
581 // 发送 Restarting 消息
582 ctx := &Context{Self: cell.pid, system: s, ctx: cell.ctx}
583 cell.actor.Receive(ctx, &Restarting{})
584
585 // 重新发送 Started 消息
586 s.Send(cell.pid, &Started{})
587
588 cell.stateMu.Lock()
589 cell.state = actorStateRunning
590 cell.stateMu.Unlock()
591
592 actorLog.Info(context.Background(), "actor restarted", map[string]any{"actor_id": cell.pid.ID, "total_restarts": cell.restarts})
593
594 case DirectiveStop:
595 s.Stop(cell.pid)
596
597 case DirectiveEscalate:
598 if cell.parent != nil {
599 // 将失败上报给父 Actor
600 s.Send(cell.parent, &Terminated{Who: cell.pid})
601 }
602 s.Stop(cell.pid)
603 }
604}
605
606// restartAllSiblings 重启所有兄弟 Actor(用于 AllForOne 策略)
607func (s *System) restartAllSiblings(child *PID) {

Callers 1

handleFailureMethod · 0.95

Calls 4

SendMethod · 0.95
StopMethod · 0.95
InfoMethod · 0.65
ReceiveMethod · 0.65

Tested by

no test coverage detected