forked from viphxin/xingo
/
xingo.go
64 lines (57 loc) · 1.93 KB
/
xingo.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
package xingo
import (
_ "github.com/timesto/xingo/fnet"
_ "github.com/timesto/xingo/timer"
"github.com/timesto/xingo/telnetcmd"
"github.com/timesto/xingo/clusterserver"
"github.com/timesto/xingo/sys_rpc"
"github.com/timesto/xingo/utils"
"github.com/timesto/xingo/fserver"
"github.com/timesto/xingo/cluster"
"github.com/timesto/xingo/logger"
"fmt"
"github.com/timesto/xingo/iface"
)
func NewXingoTcpServer() iface.Iserver{
//do something
//debugport 是否开放
if utils.GlobalObject.DebugPort > 0{
if utils.GlobalObject.Host != ""{
fserver.NewTcpServer("telnet_server", "tcp4", utils.GlobalObject.Host,
utils.GlobalObject.DebugPort, 100, cluster.NewTelnetProtocol()).Start()
}else{
fserver.NewTcpServer("telnet_server", "tcp4", "127.0.0.1",
utils.GlobalObject.DebugPort, 100, cluster.NewTelnetProtocol()).Start()
}
logger.Debug(fmt.Sprintf("telnet tool start: %s:%d.", utils.GlobalObject.Host, utils.GlobalObject.DebugPort))
}
//add command
if utils.GlobalObject.CmdInterpreter != nil{
utils.GlobalObject.CmdInterpreter.AddCommand(telnetcmd.NewPprofCpuCommand())
}
s := fserver.NewServer()
return s
}
func NewXingoMaster(cfg string) *clusterserver.Master{
s := clusterserver.NewMaster(cfg)
//add rpc
s.AddRpcRouter(&sys_rpc.MasterRpc{})
//add command
if utils.GlobalObject.CmdInterpreter != nil{
utils.GlobalObject.CmdInterpreter.AddCommand(telnetcmd.NewPprofCpuCommand())
utils.GlobalObject.CmdInterpreter.AddCommand(telnetcmd.NewCloseServerCommand())
utils.GlobalObject.CmdInterpreter.AddCommand(telnetcmd.NewReloadCfgCommand())
}
return s
}
func NewXingoCluterServer(nodename, cfg string) *clusterserver.ClusterServer{
s := clusterserver.NewClusterServer(nodename,cfg)
//add rpc
s.AddRpcRouter(&sys_rpc.ChildRpc{})
s.AddRpcRouter(&sys_rpc.RootRpc{})
//add cmd
if utils.GlobalObject.CmdInterpreter != nil{
utils.GlobalObject.CmdInterpreter.AddCommand(telnetcmd.NewPprofCpuCommand())
}
return s
}