NewSystemWithConfig 使用配置创建 Actor 系统
(name string, config *SystemConfig)
| 137 | |
| 138 | // NewSystemWithConfig 使用配置创建 Actor 系统 |
| 139 | func NewSystemWithConfig(name string, config *SystemConfig) *System { |
| 140 | if config == nil { |
| 141 | config = DefaultSystemConfig() |
| 142 | } |
| 143 | |
| 144 | ctx, cancel := context.WithCancel(context.Background()) |
| 145 | |
| 146 | s := &System{ |
| 147 | name: name, |
| 148 | actors: make(map[string]*actorCell), |
| 149 | mailbox: make(chan envelope, config.MailboxSize), |
| 150 | deadLetters: make(chan envelope, config.DeadLetterSize), |
| 151 | ctx: ctx, |
| 152 | cancel: cancel, |
| 153 | config: config, |
| 154 | stats: &SystemStats{ |
| 155 | StartTime: time.Now(), |
| 156 | }, |
| 157 | } |
| 158 | |
| 159 | s.isRunning.Store(true) |
| 160 | |
| 161 | // 启动消息分发器 |
| 162 | s.wg.Add(1) |
| 163 | go s.dispatcher() |
| 164 | |
| 165 | // 启动死信处理器 |
| 166 | if config.EnableDeadLetterLogging { |
| 167 | s.wg.Add(1) |
| 168 | go s.deadLetterHandler() |
| 169 | } |
| 170 | |
| 171 | actorLog.Info(context.Background(), "system started", map[string]any{"name": name}) |
| 172 | return s |
| 173 | } |
| 174 | |
| 175 | // Name 返回系统名称 |
| 176 | func (s *System) Name() string { |