applyDirective 应用监督指令
(cell *actorCell, directive Directive)
| 567 | |
| 568 | // applyDirective 应用监督指令 |
| 569 | func (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 策略) |
| 607 | func (s *System) restartAllSiblings(child *PID) { |
no test coverage detected