-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathactor_wrapper.go
More file actions
95 lines (83 loc) · 2.18 KB
/
actor_wrapper.go
File metadata and controls
95 lines (83 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package grain
import "sync"
type actorIdWrapper struct {
cacheParse
fullPath string
system ISystem
cacheRemote *cacheRemote
sync.RWMutex
}
func newDirectActorRef(kind string, name string, addr string, system ISystem) ActorRef {
ret := &actorIdWrapper{
fullPath: defaultActDirect + "/" + kind + "/" + name + "@" + addr,
system: system,
}
ret.parseCache()
return ret
}
func newClusterActorRef(kind string, name string, system ISystem) ActorRef {
ret := &actorIdWrapper{
fullPath: defaultActCluster + "/" + kind + "/" + name,
system: system,
}
ret.parseCache()
return ret
}
func newActorRefFromAID(aid string, system ISystem) ActorRef {
ret := &actorIdWrapper{
fullPath: aid,
system: system,
}
ret.parseCache()
return ret
}
func (x *actorIdWrapper) parseCache() {
typ, kind, name, directAddr := parseCache(x.fullPath)
x.cacheParse = cacheParse{
d8c: typ,
kind: kind,
name: name,
directAddr: directAddr,
}
}
func (x *actorIdWrapper) GetId() string { return x.fullPath }
// String ...
func (x *actorIdWrapper) String() string { return x.fullPath }
// isDirect ...
func (x *actorIdWrapper) isDirect() bool { return x.GetType() == defaultActDirect }
// isCluster ...
func (x *actorIdWrapper) isCluster() bool { return x.GetType() == defaultActCluster }
// isAsk ...
func (x *actorIdWrapper) isAsk() bool { return x.GetKind() == defaultReplyKind }
// GetRemoteAddrCache ...
// @return remote addr
// @return remote changed
func (x *actorIdWrapper) getRemoteAddrCache() (string, bool) {
if !x.isCluster() {
return "", false
}
//
nodes, version := x.GetSystem().GetProvider().GetNodes()
vCache := x.cacheRemote
changed := false
if vCache == nil || vCache.version != version {
x.Lock()
//double check
if vCache == nil || vCache.version != version {
cacheAddr := x.GetSystem().getAddrHash().CalcAddrByKind8Name(nodes, x.GetKind(), x.GetName())
if cacheAddr == "" {
x.Unlock()
return "", false
}
changed = vCache == nil || vCache.remoteAddr != cacheAddr
vCache = &cacheRemote{version, cacheAddr}
x.cacheRemote = vCache
}
x.Unlock()
}
//
if vCache == nil {
return "", changed
}
return vCache.remoteAddr, changed
}