1 Star 2 Fork 0

李文建 / light-protoactor-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
routeractor_group.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
李文建 提交于 2017-07-17 17:46 . 1.git.oschina.net替换成gitee.com
package router
import (
"sync"
"gitee.com/lwj8507/light-protoactor-go/actor"
)
type groupRouterActor struct {
props *actor.Props
config RouterConfig
state Interface
wg sync.WaitGroup
}
func (a *groupRouterActor) Receive(context actor.Context) {
switch m := context.Message().(type) {
case *actor.Started:
a.config.OnStarted(context, a.props, a.state)
a.wg.Done()
case *AddRoutee:
r := a.state.GetRoutees()
if r.Contains(m.PID) {
return
}
context.Watch(m.PID)
r.Add(m.PID)
a.state.SetRoutees(r)
case *RemoveRoutee:
r := a.state.GetRoutees()
if !r.Contains(m.PID) {
return
}
context.Unwatch(m.PID)
r.Remove(m.PID)
a.state.SetRoutees(r)
case *BroadcastMessage:
msg := m.Message
sender := context.Sender()
a.state.GetRoutees().ForEach(func(i int, pid actor.PID) {
actor.Request(&pid, msg, sender)
})
case *GetRoutees:
r := a.state.GetRoutees()
routees := make([]*actor.PID, r.Len())
r.ForEach(func(i int, pid actor.PID) {
routees[i] = &pid
})
context.Respond(&Routees{routees})
}
}
Go
1
https://gitee.com/lwj8507/light-protoactor-go.git
git@gitee.com:lwj8507/light-protoactor-go.git
lwj8507
light-protoactor-go
light-protoactor-go
013e33d7022f

搜索帮助