代码拉取完成,页面将自动刷新
package router
import (
"math/rand"
"gitee.com/wujianhai/protoactor-go/actor"
)
type randomGroupRouter struct {
GroupRouter
}
type randomPoolRouter struct {
PoolRouter
}
type randomRouterState struct {
routees *actor.PIDSet
sender actor.SenderContext
}
func (state *randomRouterState) SetSender(sender actor.SenderContext) {
state.sender = sender
}
func (state *randomRouterState) SetRoutees(routees *actor.PIDSet) {
state.routees = routees
}
func (state *randomRouterState) GetRoutees() *actor.PIDSet {
return state.routees
}
func (state *randomRouterState) RouteMessage(message interface{}) {
pid := randomRoutee(state.routees)
state.sender.Send(pid, message)
}
func NewRandomPool(size int, opts ...actor.PropsOption) *actor.Props {
return (&actor.Props{}).
Configure(actor.WithSpawnFunc(spawner(&randomPoolRouter{PoolRouter{PoolSize: size}}))).
Configure(opts...)
}
func NewRandomGroup(routees ...*actor.PID) *actor.Props {
return (&actor.Props{}).Configure(actor.WithSpawnFunc(spawner(&randomGroupRouter{GroupRouter{Routees: actor.NewPIDSet(routees...)}})))
}
func (config *randomPoolRouter) CreateRouterState() State {
return &randomRouterState{}
}
func (config *randomGroupRouter) CreateRouterState() State {
return &randomRouterState{}
}
func randomRoutee(routees *actor.PIDSet) *actor.PID {
l := routees.Len()
r := rand.Intn(l)
pid := routees.Get(r)
return pid
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。