From 1e0148bd50233f8f919a2a2ccc5dd073bf9471aa Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 12 Aug 2023 19:05:12 +0800 Subject: [PATCH] 1 --- app.go | 40 ++++++++++++++-------------------------- global.go | 4 ++-- httpserver.go | 29 +++++++++++++++-------------- types.go | 2 +- 4 files changed, 32 insertions(+), 43 deletions(-) diff --git a/app.go b/app.go index 7edb974..eab6569 100644 --- a/app.go +++ b/app.go @@ -16,7 +16,7 @@ type App_ struct { pkgName string flags map[int32]int32 servicing bool - contextHash map[int32]q5.XParams + contextHash map[int32]q5.Args loopCond *sync.Cond imTopNode *IMMsgNode imBotNode *IMMsgNode @@ -26,7 +26,7 @@ type App_ struct { chGoLoopWait chan int64 nowTime time.Time nowUnixNano int64 - imMsgHandlers [1024]func(int16,*q5.XParams) + imMsgHandlers [1024]func(int16, q5.Args) maxRunDelay int64 maxScheduleTime int64 updateFunc func () @@ -36,22 +36,11 @@ func (this *App_) Init(updateFunc func ()) { this.updateFunc = updateFunc this.nowTime = time.Now() atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano()) - _Timer = &q5.Timer{} + _Timer = &q5.XTimer{} _Timer.Init( func (context interface{}) int64 { return q5.GetTickCount() }, - func (context interface{}, isFirstAdd bool, milliSeconds int32, tick int64) int64 { - nowTime := time.Now().Unix() - todayPassedSeconds := nowTime - q5.GetDaySeconds(nowTime) - expires := (tick - todayPassedSeconds * 1000) + int64(milliSeconds) - if isFirstAdd { - if expires <= tick { - expires += 1000 * 3600 * 24 - } - } - return expires - }, nil, 1000 * 60, 5000) @@ -123,7 +112,7 @@ func (this *App_) HasFlag(flag int32) bool { return ok } -func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) { +func (this *App_) AddIMMsg(msgId int16, params q5.Args) { p := new(IMMsgNode) p.msgId = msgId p.params = params @@ -141,7 +130,7 @@ func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) { this.loopCond.Broadcast() } -func (this *App_) RegisterIMMsgHandle(msgId int16, handle func(int16,*q5.XParams)) { +func (this *App_) RegisterIMMsgHandle(msgId int16, handle func(int16,q5.Args)) { this.imMsgHandlers[msgId] = handle } @@ -208,15 +197,14 @@ func (this *App_) dispatchIMMsg() { } func (this *App_) installTimer() { - Timer().AddRepeatTimer(1000 * 60, - func (params* q5.XParams) { - - }, - func (params* q5.XParams) { - SysLog().Info("max_run_delay:%d max_schedule_time:%d", - App.maxRunDelay, - App.maxScheduleTime) - App.maxRunDelay = 0 - App.maxScheduleTime = 0 + 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 + } }) } diff --git a/global.go b/global.go index 785e401..3e511a0 100644 --- a/global.go +++ b/global.go @@ -3,11 +3,11 @@ package f5 import "q5" var App *App_ -var _Timer *q5.Timer +var _Timer *q5.XTimer var _SysLog *SysLog_ var _TgLog *TGLog_ -func Timer() *q5.Timer { +func Timer() *q5.XTimer { return _Timer } diff --git a/httpserver.go b/httpserver.go index 703502c..fa061e7 100644 --- a/httpserver.go +++ b/httpserver.go @@ -42,21 +42,22 @@ func (this *HttpServer) Init(serviceName string, logOutputTime int32) *HttpServe }) SysLog().Info("HttpServer.Init") if logOutputTime > 0 { - Timer().AddRepeatTimer( + Timer().SetInterval( logOutputTime, - func (params* q5.XParams) { - params.Sender.SetString(serviceName) - }, - func (params* q5.XParams) { - SysLog().Info("%s maxHandleTime:%d totalRequestTimes:%d okTimes:%d pageNotFoundTimes:%d", - params.Sender.GetString(), - this.maxHandleTime, - this.totalRequestTimes, - this.okTimes, - this.pageNotFoundTimes) - this.maxHandleTime = 0 - this.okTimes = 0 - this.pageNotFoundTimes = 0 + func (ev int32, params *q5.Args) { + if ev == q5.TIMER_EXEC_EVENT { + /* + SysLog().Info("%s maxHandleTime:%d totalRequestTimes:%d okTimes:%d pageNotFoundTimes:%d", + params.Sender.GetString(), + this.maxHandleTime, + this.totalRequestTimes, + this.okTimes, + this.pageNotFoundTimes) + this.maxHandleTime = 0 + this.okTimes = 0 + this.pageNotFoundTimes = 0 + */ + } }) } return this diff --git a/types.go b/types.go index 0a14770..89a0c37 100644 --- a/types.go +++ b/types.go @@ -17,7 +17,7 @@ type MsgNode struct { type IMMsgNode struct { msgId int16 - params *q5.XParams + params q5.Args next *IMMsgNode }