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

Method processMessage

pkg/actor/system.go:487–535  ·  view source on GitHub ↗

processMessage 处理单条消息

(cell *actorCell, env envelope)

Source from the content-addressed store, hash-verified

485
486// processMessage 处理单条消息
487func (s *System) processMessage(cell *actorCell, env envelope) {
488 // panic 恢复
489 defer func() {
490 if r := recover(); r != nil {
491 if s.config.PanicHandler != nil {
492 s.config.PanicHandler(cell.pid, env.message, r)
493 }
494 // 触发监督策略
495 s.handleFailure(cell, env.message, r)
496 }
497 }()
498
499 // 创建上下文,支持 Request/Response
500 ctx := &Context{
501 Self: cell.pid,
502 Sender: env.sender,
503 Parent: cell.parent,
504 Children: s.getChildrenPIDs(cell),
505 system: s,
506 ctx: cell.ctx,
507 message: env.message,
508 }
509
510 // 如果是 Request 模式,设置响应通道和请求 context
511 if env.response != nil {
512 ctx.responseChan = env.response
513 ctx.requestCtx = env.ctx
514 }
515
516 // 处理系统消息
517 switch msg := env.message.(type) {
518 case *PoisonPill:
519 // 发送 Stopping 消息
520 cell.actor.Receive(ctx, &Stopping{})
521 return
522
523 case *Watch:
524 cell.watchers[msg.Watcher.ID] = msg.Watcher
525 return
526
527 case *Unwatch:
528 delete(cell.watchers, msg.Watcher.ID)
529 return
530 }
531
532 // 处理用户消息
533 cell.actor.Receive(ctx, env.message)
534 atomic.AddInt64(&s.stats.ProcessedMsgs, 1)
535}
536
537// handleFailure 处理 Actor 失败
538func (s *System) handleFailure(cell *actorCell, msg Message, err any) {

Callers 1

actorLoopMethod · 0.95

Calls 4

handleFailureMethod · 0.95
getChildrenPIDsMethod · 0.95
deleteFunction · 0.85
ReceiveMethod · 0.65

Tested by

no test coverage detected