1 Star 0 Fork 0

jack/protoactor-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
actor_system.go 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
490689386@qq.com 提交于 2025-05-19 14:50 +08:00 . 初始化
package actor
import (
"log/slog"
"net"
"strconv"
"gitee.com/wujianhai/protoactor-go/eventstream"
"gitee.com/wujianhai/protoactor-go/extensions"
"github.com/lithammer/shortuuid/v4"
)
//goland:noinspection GoNameStartsWithPackageName
type ActorSystem struct {
ProcessRegistry *ProcessRegistryValue
Root *RootContext
EventStream *eventstream.EventStream
Guardians *guardiansValue
DeadLetter *deadLetterProcess
Extensions *extensions.Extensions
Config *Config
ID string
stopper chan struct{}
logger *slog.Logger
}
func (as *ActorSystem) Logger() *slog.Logger {
return as.logger
}
func (as *ActorSystem) NewLocalPID(id string) *PID {
return NewPID(as.ProcessRegistry.Address, id)
}
func (as *ActorSystem) Address() string {
return as.ProcessRegistry.Address
}
func (as *ActorSystem) GetHostPort() (host string, port int, err error) {
addr := as.ProcessRegistry.Address
if h, p, e := net.SplitHostPort(addr); e != nil {
if addr != localAddress {
err = e
}
host = localAddress
port = -1
} else {
host = h
port, err = strconv.Atoi(p)
}
return
}
func (as *ActorSystem) Shutdown() {
close(as.stopper)
}
func (as *ActorSystem) IsStopped() bool {
select {
case <-as.stopper:
return true
default:
return false
}
}
func NewActorSystem(options ...ConfigOption) *ActorSystem {
config := Configure(options...)
return NewActorSystemWithConfig(config)
}
func NewActorSystemWithConfig(config *Config) *ActorSystem {
system := &ActorSystem{}
system.ID = shortuuid.New()
system.Config = config
system.logger = config.LoggerFactory(system)
system.ProcessRegistry = NewProcessRegistry(system)
system.Root = NewRootContext(system, EmptyMessageHeader)
system.Guardians = NewGuardians(system)
system.EventStream = eventstream.NewEventStream()
system.DeadLetter = NewDeadLetter(system)
system.Extensions = extensions.NewExtensions()
SubscribeSupervision(system)
system.Extensions.Register(NewMetrics(system, config.MetricsProvider))
system.ProcessRegistry.Add(NewEventStreamProcess(system), "eventstream")
system.stopper = make(chan struct{})
system.Logger().Info("actor system started", slog.String("id", system.ID))
return system
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wujianhai/protoactor-go.git
git@gitee.com:wujianhai/protoactor-go.git
wujianhai
protoactor-go
protoactor-go
5633fe2499dd

搜索帮助