mirror of
https://github.com/duanhf2012/origin.git
synced 2026-05-13 02:17:35 +08:00
Module模块新增OnRunEnd
This commit is contained in:
@@ -16,7 +16,7 @@ const (
|
|||||||
type IModule interface {
|
type IModule interface {
|
||||||
OnInit() error //Module初始化时调用
|
OnInit() error //Module初始化时调用
|
||||||
OnRun() bool //Module运行时调用
|
OnRun() bool //Module运行时调用
|
||||||
|
OnEndRun()
|
||||||
SetModuleId(moduleId uint32) //手动设置ModuleId
|
SetModuleId(moduleId uint32) //手动设置ModuleId
|
||||||
GetModuleId() uint32 //获取ModuleId
|
GetModuleId() uint32 //获取ModuleId
|
||||||
GetModuleById(moduleId uint32) IModule //通过ModuleId获取Module
|
GetModuleById(moduleId uint32) IModule //通过ModuleId获取Module
|
||||||
@@ -217,6 +217,9 @@ func (slf *BaseModule) OnRun() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (slf *BaseModule) OnEndRun() {
|
||||||
|
}
|
||||||
|
|
||||||
func (slf *BaseModule) SetOwner(ownerModule IModule) {
|
func (slf *BaseModule) SetOwner(ownerModule IModule) {
|
||||||
slf.ownerModule = ownerModule
|
slf.ownerModule = ownerModule
|
||||||
}
|
}
|
||||||
@@ -260,12 +263,14 @@ func (slf *BaseModule) RunModule(module IModule) {
|
|||||||
defer slf.WaitGroup.Done()
|
defer slf.WaitGroup.Done()
|
||||||
for {
|
for {
|
||||||
if atomic.LoadInt32(&slf.corouterstatus) != 0 {
|
if atomic.LoadInt32(&slf.corouterstatus) != 0 {
|
||||||
|
slf.OnEndRun()
|
||||||
GetLogger().Printf(LEVER_INFO, "Stopping module %T id is %d...", slf.GetSelf(), module.GetModuleId())
|
GetLogger().Printf(LEVER_INFO, "Stopping module %T id is %d...", slf.GetSelf(), module.GetModuleId())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-slf.ExitChan:
|
case <-slf.ExitChan:
|
||||||
|
slf.OnEndRun()
|
||||||
GetLogger().Printf(LEVER_INFO, "Stopping module %T...", slf.GetSelf())
|
GetLogger().Printf(LEVER_INFO, "Stopping module %T...", slf.GetSelf())
|
||||||
fmt.Println("Stopping module %T...", slf.GetSelf())
|
fmt.Println("Stopping module %T...", slf.GetSelf())
|
||||||
return
|
return
|
||||||
@@ -273,6 +278,7 @@ func (slf *BaseModule) RunModule(module IModule) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if module.OnRun() == false {
|
if module.OnRun() == false {
|
||||||
|
slf.OnEndRun()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user