mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
优化启动流程整理代码
This commit is contained in:
@@ -70,7 +70,6 @@ func (slf *Cluster) Init(currentNodeId int) error{
|
|||||||
rpcinfo.client = &rpc.Client{}
|
rpcinfo.client = &rpc.Client{}
|
||||||
if nodeinfo.NodeId == currentNodeId {
|
if nodeinfo.NodeId == currentNodeId {
|
||||||
rpcinfo.client.Connect("")
|
rpcinfo.client.Connect("")
|
||||||
//rpcinfo.client.Connect(nodeinfo.ListenAddr)
|
|
||||||
}else{
|
}else{
|
||||||
rpcinfo.client.Connect(nodeinfo.ListenAddr)
|
rpcinfo.client.Connect(nodeinfo.ListenAddr)
|
||||||
}
|
}
|
||||||
|
|||||||
34
node/node.go
34
node/node.go
@@ -64,34 +64,28 @@ func GetNodeId() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initNode(id int){
|
func initNode(id int){
|
||||||
nodeId = id
|
|
||||||
//1.初始化集群
|
//1.初始化集群
|
||||||
|
nodeId = id
|
||||||
err := cluster.GetCluster().Init(GetNodeId())
|
err := cluster.GetCluster().Init(GetNodeId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("read system config is error %+v",err)
|
log.Fatal("read system config is error %+v",err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//2.service模块初始化
|
//2.setup service
|
||||||
service.Init(closeSig)
|
|
||||||
|
|
||||||
//3.setup service
|
|
||||||
for _,s := range preSetupService {
|
for _,s := range preSetupService {
|
||||||
//是否配置的service
|
//是否配置的service
|
||||||
if cluster.GetCluster().IsConfigService(s.GetName()) == false {
|
if cluster.GetCluster().IsConfigService(s.GetName()) == false {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pServiceCfg := cluster.GetCluster().GetServiceCfg(nodeId,s.GetName())
|
||||||
|
s.Init(s,cluster.GetRpcClient,cluster.GetRpcServer,pServiceCfg)
|
||||||
|
|
||||||
service.Setup(s)
|
service.Setup(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
//4.init service
|
//3.service初始化
|
||||||
for _,s := range preSetupService {
|
service.Init(closeSig)
|
||||||
//是否配置的service
|
|
||||||
if cluster.GetCluster().IsConfigService(s.GetName()) == false {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
pServiceCfg := cluster.GetCluster().GetServiceCfg(nodeId,s.GetName())
|
|
||||||
s.Init(s,cluster.GetRpcClient,cluster.GetRpcServer,pServiceCfg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
@@ -117,16 +111,25 @@ func stopNode(arg interface{}) error {
|
|||||||
|
|
||||||
func startNode(paramNodeId interface{}) error {
|
func startNode(paramNodeId interface{}) error {
|
||||||
log.Release("Start running server.")
|
log.Release("Start running server.")
|
||||||
|
|
||||||
|
//1.初始化node
|
||||||
initNode(paramNodeId.(int))
|
initNode(paramNodeId.(int))
|
||||||
|
|
||||||
|
//2.运行集群
|
||||||
cluster.GetCluster().Start()
|
cluster.GetCluster().Start()
|
||||||
|
|
||||||
|
//3.运行service
|
||||||
service.Start()
|
service.Start()
|
||||||
|
|
||||||
|
//4.记录进程id号
|
||||||
writeProcessPid()
|
writeProcessPid()
|
||||||
|
|
||||||
|
//5.监听程序退出信号&性能报告
|
||||||
bRun := true
|
bRun := true
|
||||||
var pProfilerTicker *time.Ticker = &time.Ticker{}
|
var pProfilerTicker *time.Ticker = &time.Ticker{}
|
||||||
if profilerInterval>0 {
|
if profilerInterval>0 {
|
||||||
pProfilerTicker = time.NewTicker(profilerInterval)
|
pProfilerTicker = time.NewTicker(profilerInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
for bRun {
|
for bRun {
|
||||||
select {
|
select {
|
||||||
case <-sigs:
|
case <-sigs:
|
||||||
@@ -137,6 +140,7 @@ func startNode(paramNodeId interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//6.退出
|
||||||
close(closeSig)
|
close(closeSig)
|
||||||
service.WaitStop()
|
service.WaitStop()
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ func (slf *Service) Init(iservice IService,getClientFun rpc.FuncRpcClient,getSer
|
|||||||
slf.serviceCfg = serviceCfg
|
slf.serviceCfg = serviceCfg
|
||||||
slf.gorouterNum = 1
|
slf.gorouterNum = 1
|
||||||
slf.eventHandler.Init(&slf.eventProcessor)
|
slf.eventHandler.Init(&slf.eventProcessor)
|
||||||
slf.self.OnInit()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *Service) SetGoRouterNum(gorouterNum int32) bool {
|
func (slf *Service) SetGoRouterNum(gorouterNum int32) bool {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import "github.com/duanhf2012/origin/log"
|
|
||||||
|
|
||||||
//本地所有的service
|
//本地所有的service
|
||||||
var mapServiceName map[string]IService
|
var mapServiceName map[string]IService
|
||||||
|
|
||||||
@@ -13,24 +11,18 @@ func Init(chanCloseSig chan bool) {
|
|||||||
closeSig=chanCloseSig
|
closeSig=chanCloseSig
|
||||||
|
|
||||||
for _,s := range mapServiceName {
|
for _,s := range mapServiceName {
|
||||||
err := s.OnInit()
|
s.OnInit()
|
||||||
if err!=nil {
|
|
||||||
log.Fatal("start server fail :%+v.....",err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Setup(s IService) bool {
|
func Setup(s IService) bool {
|
||||||
|
|
||||||
_,ok := mapServiceName[s.GetName()]
|
_,ok := mapServiceName[s.GetName()]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//s.Init(s)
|
|
||||||
mapServiceName[s.GetName()] = s
|
mapServiceName[s.GetName()] = s
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user