1
This commit is contained in:
parent
0917867fac
commit
f38d0d1419
54
app.go
54
app.go
@ -9,6 +9,10 @@ import (
|
||||
"q5"
|
||||
)
|
||||
|
||||
type F5App interface {
|
||||
GetPkgName() string
|
||||
}
|
||||
|
||||
type UserApp interface {
|
||||
GetPkgName() string
|
||||
Init()
|
||||
@ -16,7 +20,7 @@ type UserApp interface {
|
||||
UnInit()
|
||||
}
|
||||
|
||||
type F5App struct {
|
||||
type app struct {
|
||||
nodeId int
|
||||
instanceId int
|
||||
terminated bool
|
||||
@ -39,7 +43,7 @@ type F5App struct {
|
||||
userApp UserApp
|
||||
}
|
||||
|
||||
func (this *F5App) init(userApp UserApp) {
|
||||
func (this *app) init(userApp UserApp) {
|
||||
this.userApp = userApp
|
||||
this.nowTime = time.Now()
|
||||
atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano())
|
||||
@ -71,14 +75,14 @@ func (this *F5App) init(userApp UserApp) {
|
||||
this.userApp.Init()
|
||||
}
|
||||
|
||||
func (this *F5App) unInit() {
|
||||
func (this *app) unInit() {
|
||||
this.chGoLoopTimerExit <- 1
|
||||
_Timer.UnInit()
|
||||
_Timer = nil
|
||||
this.userApp.UnInit()
|
||||
}
|
||||
|
||||
func (this *F5App) run() {
|
||||
func (this *app) run() {
|
||||
for !this.terminated {
|
||||
this.nowTime = time.Now()
|
||||
atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano())
|
||||
@ -96,32 +100,32 @@ func (this *F5App) run() {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *F5App) NewUuid() int64 {
|
||||
func (this *app) NewUuid() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *F5App) GetInstanceId() uint32 {
|
||||
func (this *app) GetInstanceId() uint32 {
|
||||
return uint32(this.instanceId)
|
||||
}
|
||||
|
||||
func (this *F5App) GetNodeId() uint32 {
|
||||
func (this *app) GetNodeId() uint32 {
|
||||
return uint32(this.nodeId)
|
||||
}
|
||||
|
||||
func (this *F5App) GetPkgName() string {
|
||||
func (this *app) GetPkgName() string {
|
||||
return this.pkgName
|
||||
}
|
||||
|
||||
func (this *F5App) SetPkgName(pkgName string) {
|
||||
func (this *app) SetPkgName(pkgName string) {
|
||||
this.pkgName = pkgName
|
||||
}
|
||||
|
||||
func (this *F5App) HasFlag(flag int32) bool {
|
||||
func (this *app) HasFlag(flag int32) bool {
|
||||
_, ok := this.flags[flag]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (this *F5App) AddIMMsg(msgId int16, params q5.Args) {
|
||||
func (this *app) AddIMMsg(msgId int16, params q5.Args) {
|
||||
p := new(IMMsgNode)
|
||||
p.msgId = msgId
|
||||
p.params = params
|
||||
@ -139,11 +143,11 @@ func (this *F5App) AddIMMsg(msgId int16, params q5.Args) {
|
||||
this.loopCond.Broadcast()
|
||||
}
|
||||
|
||||
func (this *F5App) RegisterIMMsgHandle(msgId int16, handle func(int16,q5.Args)) {
|
||||
func (this *app) RegisterIMMsgHandle(msgId int16, handle func(int16,q5.Args)) {
|
||||
this.imMsgHandlers[msgId] = handle
|
||||
}
|
||||
|
||||
func (this *F5App) goLoopTimer() {
|
||||
func (this *app) goLoopTimer() {
|
||||
var waitMs int64 = 1000 * 10
|
||||
for {
|
||||
select {
|
||||
@ -160,33 +164,33 @@ func (this *F5App) goLoopTimer() {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *F5App) schedule() {
|
||||
func (this *app) schedule() {
|
||||
this.chGoLoopWait <- Timer().GetIdleTime()
|
||||
this.loopCond.L.Lock()
|
||||
this.loopCond.Wait()
|
||||
this.loopCond.L.Unlock()
|
||||
}
|
||||
|
||||
func (this *F5App) NotifyLoopCond() {
|
||||
func (this *app) NotifyLoopCond() {
|
||||
this.loopCond.Broadcast()
|
||||
}
|
||||
|
||||
func (this *F5App) NowUnix() int64 {
|
||||
func (this *app) NowUnix() int64 {
|
||||
return this.nowUnixNano / int64(time.Second)
|
||||
}
|
||||
|
||||
func (this *F5App) NowUnixMilli() int64 {
|
||||
func (this *app) NowUnixMilli() int64 {
|
||||
return this.nowUnixNano / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
func (this *F5App) NowUnixNano() int64 {
|
||||
func (this *app) NowUnixNano() int64 {
|
||||
return this.nowUnixNano
|
||||
}
|
||||
|
||||
func (this *F5App) outputRuningLog() {
|
||||
func (this *app) outputRuningLog() {
|
||||
}
|
||||
|
||||
func (this *F5App) dispatchIMMsg() {
|
||||
func (this *app) dispatchIMMsg() {
|
||||
this.imMsgMutex.Lock()
|
||||
this.imWorkNode = this.imTopNode
|
||||
this.imTopNode = nil
|
||||
@ -202,15 +206,15 @@ func (this *F5App) dispatchIMMsg() {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *F5App) installTimer() {
|
||||
func (this *app) installTimer() {
|
||||
Timer().SetInterval(1000 * 60,
|
||||
func (ev int32, params *q5.Args) {
|
||||
if ev == q5.TIMER_EXEC_EVENT {
|
||||
SysLog().Info("max_run_delay:%d max_schedule_time:%d",
|
||||
App().maxRunDelay,
|
||||
App().maxScheduleTime)
|
||||
App().maxRunDelay = 0
|
||||
App().maxScheduleTime = 0
|
||||
_app.maxRunDelay,
|
||||
_app.maxScheduleTime)
|
||||
_app.maxRunDelay = 0
|
||||
_app.maxScheduleTime = 0
|
||||
}
|
||||
})
|
||||
}
|
||||
|
14
global.go
14
global.go
@ -2,7 +2,7 @@ package f5
|
||||
|
||||
import "q5"
|
||||
|
||||
var app *F5App
|
||||
var _app *app
|
||||
var _Timer *q5.XTimer
|
||||
var _SysLog *SysLog_
|
||||
var _TgLog *TGLog_
|
||||
@ -19,13 +19,13 @@ func TgLog() *TGLog_ {
|
||||
return _TgLog
|
||||
}
|
||||
|
||||
func App() *F5App {
|
||||
return app
|
||||
func GetApp() F5App {
|
||||
return _app
|
||||
}
|
||||
|
||||
func Run(userApp UserApp) {
|
||||
app = new(F5App)
|
||||
app.init(userApp)
|
||||
app.run()
|
||||
app.unInit()
|
||||
_app = new(app)
|
||||
_app.init(userApp)
|
||||
_app.run()
|
||||
_app.unInit()
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ func (this *SysLog_) goSaveToFile() {
|
||||
this.botNode = nil
|
||||
this.msgMutex.Unlock()
|
||||
if workNode != nil {
|
||||
logDir := fmt.Sprintf(SYS_LOG_ROOT, App().GetPkgName())
|
||||
logDir := fmt.Sprintf(SYS_LOG_ROOT, GetApp().GetPkgName())
|
||||
fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102"))
|
||||
q5.ForceCreateDir(logDir)
|
||||
if f, err := os.OpenFile(logDir + fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user