forked from TarsCloud/TarsGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodef.go
56 lines (50 loc) · 1.17 KB
/
nodef.go
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
package tars
import (
"os"
"github.com/TarsCloud/TarsGo/tars/protocol/res/nodef"
)
// NodeFHelper is helper struct.
type NodeFHelper struct {
comm *Communicator
si nodef.ServerInfo
sf *nodef.ServerF
}
// SetNodeInfo sets node information with communicator, node name, app name, server and container name
func (n *NodeFHelper) SetNodeInfo(comm *Communicator, node string, app string, server string, container string) {
if node == "" {
return
}
n.comm = comm
n.sf = new(nodef.ServerF)
comm.StringToProxy(node, n.sf)
n.si = nodef.ServerInfo{
app,
server,
int32(os.Getpid()),
"",
//"tars",
//container,
}
}
// KeepAlive sends the keepalive pacakage to the node.
func (n *NodeFHelper) KeepAlive(adapter string) {
if n.sf == nil {
return
}
n.si.Pid = int32(os.Getpid())
n.si.Adapter = adapter
_, err := n.sf.KeepAlive(&n.si)
if err != nil {
TLOG.Error("keepalive fail:", adapter)
}
}
// ReportVersion report the tars version to the node.
func (n *NodeFHelper) ReportVersion(version string) {
if n.sf == nil {
return
}
_, err := n.sf.ReportVersion(n.si.Application, n.si.ServerName, version)
if err != nil {
TLOG.Error("report Version fail:")
}
}