优化启动流程整理代码

This commit is contained in:
boyce
2020-07-31 20:04:49 +08:00
parent 5e3cb7623f
commit 0d547b1e83
4 changed files with 20 additions and 26 deletions

View File

@@ -70,7 +70,6 @@ func (slf *Cluster) Init(currentNodeId int) error{
rpcinfo.client = &rpc.Client{}
if nodeinfo.NodeId == currentNodeId {
rpcinfo.client.Connect("")
//rpcinfo.client.Connect(nodeinfo.ListenAddr)
}else{
rpcinfo.client.Connect(nodeinfo.ListenAddr)
}

View File

@@ -64,34 +64,28 @@ func GetNodeId() int {
}
func initNode(id int){
nodeId = id
//1.初始化集群
nodeId = id
err := cluster.GetCluster().Init(GetNodeId())
if err != nil {
log.Fatal("read system config is error %+v",err)
}
//2.service模块初始化
service.Init(closeSig)
//3.setup service
//2.setup service
for _,s := range preSetupService {
//是否配置的service
if cluster.GetCluster().IsConfigService(s.GetName()) == false {
continue
}
pServiceCfg := cluster.GetCluster().GetServiceCfg(nodeId,s.GetName())
s.Init(s,cluster.GetRpcClient,cluster.GetRpcServer,pServiceCfg)
service.Setup(s)
}
//4.init service
for _,s := range preSetupService {
//是否配置的service
if cluster.GetCluster().IsConfigService(s.GetName()) == false {
continue
}
pServiceCfg := cluster.GetCluster().GetServiceCfg(nodeId,s.GetName())
s.Init(s,cluster.GetRpcClient,cluster.GetRpcServer,pServiceCfg)
}
//3.service初始化
service.Init(closeSig)
}
func Start() {
@@ -117,16 +111,25 @@ func stopNode(arg interface{}) error {
func startNode(paramNodeId interface{}) error {
log.Release("Start running server.")
//1.初始化node
initNode(paramNodeId.(int))
//2.运行集群
cluster.GetCluster().Start()
//3.运行service
service.Start()
//4.记录进程id号
writeProcessPid()
//5.监听程序退出信号&性能报告
bRun := true
var pProfilerTicker *time.Ticker = &time.Ticker{}
if profilerInterval>0 {
pProfilerTicker = time.NewTicker(profilerInterval)
}
for bRun {
select {
case <-sigs:
@@ -137,6 +140,7 @@ func startNode(paramNodeId interface{}) error {
}
}
//6.退出
close(closeSig)
service.WaitStop()

View File

@@ -70,7 +70,6 @@ func (slf *Service) Init(iservice IService,getClientFun rpc.FuncRpcClient,getSer
slf.serviceCfg = serviceCfg
slf.gorouterNum = 1
slf.eventHandler.Init(&slf.eventProcessor)
slf.self.OnInit()
}
func (slf *Service) SetGoRouterNum(gorouterNum int32) bool {

View File

@@ -1,7 +1,5 @@
package service
import "github.com/duanhf2012/origin/log"
//本地所有的service
var mapServiceName map[string]IService
@@ -13,24 +11,18 @@ func Init(chanCloseSig chan bool) {
closeSig=chanCloseSig
for _,s := range mapServiceName {
err := s.OnInit()
if err!=nil {
log.Fatal("start server fail :%+v.....",err)
}
s.OnInit()
}
}
func Setup(s IService) bool {
_,ok := mapServiceName[s.GetName()]
if ok == true {
return false
}
//s.Init(s)
mapServiceName[s.GetName()] = s
return true
}