mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-13 23:24:45 +08:00
去除掉全局模块
This commit is contained in:
@@ -256,29 +256,34 @@ func (slf *BaseModule) getBaseModule() *BaseModule {
|
||||
}
|
||||
|
||||
func (slf *BaseModule) RunModule(module IModule) {
|
||||
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)
|
||||
} else {
|
||||
GetLogger().Printf(LEVER_INFO, "Start module %T id is %d...", module, module.GetModuleId())
|
||||
}
|
||||
|
||||
//运行所有子模块
|
||||
slf.WaitGroup.Add(1)
|
||||
defer slf.WaitGroup.Done()
|
||||
for {
|
||||
if atomic.LoadInt32(&slf.corouterstatus) != 0 {
|
||||
slf.OnEndRun()
|
||||
GetLogger().Printf(LEVER_INFO, "Stopping module %T id is %d...", slf.GetSelf(), module.GetModuleId())
|
||||
module.OnEndRun()
|
||||
GetLogger().Printf(LEVER_INFO, "Stopping module %T id is %d...", module, module.GetModuleId())
|
||||
break
|
||||
}
|
||||
|
||||
select {
|
||||
case <-slf.ExitChan:
|
||||
slf.OnEndRun()
|
||||
GetLogger().Printf(LEVER_INFO, "Stopping module %T...", slf.GetSelf())
|
||||
fmt.Println("Stopping module %T...", slf.GetSelf())
|
||||
module.OnEndRun()
|
||||
GetLogger().Printf(LEVER_INFO, "Stopping module %T...", module)
|
||||
fmt.Printf("Stopping module %T...\n", module)
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
if module.OnRun() == false {
|
||||
slf.OnEndRun()
|
||||
module.OnEndRun()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,16 +65,19 @@ func (slf *BaseService) OnRemoveService(iservice IService) {
|
||||
|
||||
func (slf *BaseService) Init(iservice IService) error {
|
||||
slf.ownerService = iservice
|
||||
slf.servicename = fmt.Sprintf("%T", iservice)
|
||||
parts := strings.Split(slf.servicename, ".")
|
||||
if len(parts) != 2 {
|
||||
GetLogger().Printf(LEVER_ERROR, "BaseService.Init: service name is error: %q", slf.servicename)
|
||||
err := fmt.Errorf("BaseService.Init: service name is error: %q", slf.servicename)
|
||||
return err
|
||||
|
||||
if iservice.GetServiceName() == "" {
|
||||
slf.servicename = fmt.Sprintf("%T", iservice)
|
||||
parts := strings.Split(slf.servicename, ".")
|
||||
if len(parts) != 2 {
|
||||
GetLogger().Printf(LEVER_ERROR, "BaseService.Init: service name is error: %q", slf.servicename)
|
||||
err := fmt.Errorf("BaseService.Init: service name is error: %q", slf.servicename)
|
||||
return err
|
||||
}
|
||||
|
||||
slf.servicename = parts[1]
|
||||
}
|
||||
|
||||
slf.servicename = parts[1]
|
||||
slf.serviceid = InstanceServiceMgr().GenServiceID()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ type CServiceManager struct {
|
||||
}
|
||||
|
||||
func (slf *CServiceManager) Setup(s IService) bool {
|
||||
|
||||
slf.localserviceMap[s.GetServiceName()] = s
|
||||
return true
|
||||
}
|
||||
@@ -43,7 +42,6 @@ func (slf *CServiceManager) FetchService(s FetchService) IService {
|
||||
}
|
||||
|
||||
func (slf *CServiceManager) Init(logger ILogger, exit chan bool, pwaitGroup *sync.WaitGroup) bool {
|
||||
|
||||
slf.logger = logger
|
||||
for _, s := range slf.localserviceMap {
|
||||
(s.(IModule)).InitModule(exit, pwaitGroup)
|
||||
|
||||
Reference in New Issue
Block a user