修改模块初始化流程

This commit is contained in:
boyce
2019-03-22 13:23:58 +08:00
parent 589c463e7c
commit 0d28940ef8
2 changed files with 22 additions and 6 deletions

View File

@@ -209,11 +209,19 @@ func (slf *BaseModule) AddModule(module IModule) uint32 {
slf.mapModule[module.GetModuleId()] = module
//运行模块
err := module.OnInit()
if err != nil {
GetLogger().Printf(LEVER_ERROR, "Init module %T id is %d is fail,reason:%v...", module, module.GetModuleId(), err)
os.Exit(-1)
}
module.getBaseModule().OnInit()
go module.RunModule(module)
return module.GetModuleId()
}
func (slf *BaseModule) OnInit() error {
slf.bInit = true
return nil
}
@@ -264,14 +272,12 @@ func (slf *BaseModule) IsInit() bool {
}
func (slf *BaseModule) RunModule(module IModule) {
err := module.OnInit()
/*err := module.OnInit()
if err != nil {
GetLogger().Printf(LEVER_ERROR, "Start module %T id is %d is fail,reason:%v...", module, module.GetModuleId(), err)
os.Exit(-1)
}
GetLogger().Printf(LEVER_INFO, "Start module %T ...", module)
slf.bInit = true
}*/
GetLogger().Printf(LEVER_INFO, "Start Run module %T ...", module)
//运行所有子模块
timer := util.Timer{}

View File

@@ -1,8 +1,8 @@
package service
import (
"os"
"sync"
)
type IServiceManager interface {
@@ -56,6 +56,16 @@ func (slf *CServiceManager) Init(logger ILogger, exit chan bool, pwaitGroup *syn
}
func (slf *CServiceManager) Start() bool {
for _, s := range slf.localserviceMap {
err := s.(IModule).OnInit()
if err != nil {
GetLogger().Printf(LEVER_ERROR, "Init module %T id is %d is fail,reason:%v...", s.(IModule), s.(IModule).GetModuleId(), err)
os.Exit(-1)
}
s.(IModule).getBaseModule().OnInit()
}
for _, s := range slf.localserviceMap {
go (s.(IModule)).RunModule(s.(IModule))
}