代码拉取完成,页面将自动刷新
package cluster
import (
"gitee.com/wujianhai/protoactor-go/actor"
cmap "github.com/orcaman/concurrent-map"
)
type PidCacheValue struct {
cache cmap.ConcurrentMap
}
func NewPidCache() *PidCacheValue {
pidCache := &PidCacheValue{
cache: cmap.New(),
}
return pidCache
}
func key(identity string, kind string) string {
return identity + "." + kind
}
func (c *PidCacheValue) Get(identity string, kind string) (*actor.PID, bool) {
k := key(identity, kind)
v, ok := c.cache.Get(k)
if !ok {
return nil, false
}
return v.(*actor.PID), true
}
func (c *PidCacheValue) Set(identity string, kind string, pid *actor.PID) {
k := key(identity, kind)
c.cache.Set(k, pid)
}
func (c *PidCacheValue) RemoveByValue(identity string, kind string, pid *actor.PID) {
k := key(identity, kind)
c.cache.RemoveCb(k, func(key string, v interface{}, exists bool) bool {
if !exists {
return false
}
existing, _ := v.(*actor.PID)
return existing.Equal(pid)
})
}
func (c *PidCacheValue) Remove(identity string, kind string) {
k := key(identity, kind)
c.cache.Remove(k)
}
func (c *PidCacheValue) RemoveByMember(member *Member) {
addr := member.Address()
for item := range c.cache.IterBuffered() {
pid, _ := item.Val.(*actor.PID)
if pid.Address == addr {
c.cache.Remove(item.Key)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。