-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.go
96 lines (86 loc) · 2.23 KB
/
globals.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
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
96
package gonode
import (
"github.com/itfantasy/gonode/behaviors/gen_server"
"github.com/itfantasy/gonode/behaviors/logger"
"github.com/itfantasy/gonode/behaviors/monitor"
"github.com/itfantasy/gonode/behaviors/supervisor"
"github.com/itfantasy/gonode/core/errs"
"github.com/itfantasy/gonode/nets"
)
// -------------- global ----------------
var node *GoNode = nil
func init() {
node = &GoNode{}
}
func Launch() {
node.Launch()
}
func Info() *gen_server.NodeInfo {
return node.Info()
}
func Self() string {
return node.Self()
}
func Bind(behavior gen_server.GenServer) {
node.Bind(behavior)
}
func BindMonitor(monitor monitor.GenMonitor) {
node.BindMonitor(monitor)
}
func BindLogger(logWriter logger.LogWriter, logLevel int) {
node.BindLogger(logWriter, logLevel)
}
func Supervise(super supervisor.Supervisor) error {
return node.Supervise(super)
}
func Listen(url string) {
node.Listen(url)
}
func Connect(nickid string, url string) error {
return node.Connnect(nickid, url)
}
func Send(id string, msg []byte) error {
return node.Send(id, msg)
}
func SendAll(ids []string, msg []byte) []error {
return node.SendAll(ids, msg)
}
func Close(id string) error {
return node.Close(id)
}
func Label(id string) string {
return nets.Label(id)
}
func Nodes(label string) []string {
return nets.Nodes(label)
}
func IsPeer(id string) bool {
return nets.IsPeer(id)
}
func GetNodeInfo(id string) (*gen_server.NodeInfo, error) {
return node.dc.GetNodeInfo(id)
}
func GetNodeStatus(id string, ref interface{}) error {
return node.dc.GetNodeStatus(id, ref)
}
func Debug(arg0 interface{}, args ...interface{}) {
node.Logger().Log4Extend(logger.DEBUG, 1, arg0, args...)
}
func LogInfo(arg0 interface{}, args ...interface{}) {
node.Logger().Log4Extend(logger.INFO, 1, arg0, args...)
}
func LogWarn(arg0 interface{}, args ...interface{}) {
node.Logger().Log4Extend(logger.WARN, 1, arg0, args...)
}
func LogError(arg0 interface{}, args ...interface{}) {
node.Logger().Log4Extend(logger.ERROR, 1, arg0, args...)
}
func LogSource(callstack int) string {
return node.Logger().Source(callstack + 1)
}
func CustomError(errcode int, errmsg string) error {
return errs.CustomError(errcode, errmsg)
}
func ErrorInfo(err error) (int, string) {
return errs.ErrorInfo(err)
}