Documentation ¶
Index ¶
- Constants
- Variables
- func Call(des TSvieId, cmd TCmdId, args ...interface{}) (interface{}, error)
- func Caly(des TSvieId, cmd TCmdId, args []interface{}, from IServicer, done CalyHandFunc)
- func Cast(des TSvieId, cmd TCmdId, args ...interface{})
- func CombStatus(field, content string, first ...bool) string
- func ControlCount() int
- func CtrlOverview() string
- func EventCount(who IServicer) int
- func EventCountFor(des IServicer, care IServicer) int
- func EventOverview(who IServicer) string
- func EventServiceCount(des IServicer) int
- func EventServiceCountFor(des IServicer, eventId TEventId) int
- func GetCtrlMsgName(id TMsgId) string
- func GetCtrlName(id TCtrlId) string
- func GetSvieName(sId TSvieId) string
- func InitSettings()
- func Listen(des TSvieId, desEvent TEventId, care IServicer, careHandle interface{}) error
- func Load(name string, handle ISettinger) error
- func ReLoad(name string) error
- func Run(delayfun func(), sett ...*SLogSetting)
- func ServiceCount() int
- func SetCtrlMsgName(id TMsgId, name string)
- func SetCtrlName(id TCtrlId, name string)
- func SetSvieName(sId TSvieId, name string)
- func SettingContent(name string) string
- func SettingCount() int
- func SettingOverview() string
- func Shut(reason error)
- func Start(id TSvieId, handle ISeriHandler) error
- func Stop(id TSvieId, wait bool, reason error)
- func SvieOverview(wild ...bool) string
- func UnListen(des TSvieId, desEvent TEventId, care IServicer, careHandle interface{}) error
- func Work() error
- type CalyHandFunc
- type ControlHandle
- func (this *ControlHandle) HandleGore() *Gore
- func (this *ControlHandle) HandleInit(own ICtrlOwner)
- func (this *ControlHandle) HandleLaun()
- func (this *ControlHandle) HandleStat() string
- func (this *ControlHandle) HandleSusp()
- func (this *ControlHandle) HandleTerm()
- func (this *ControlHandle) HandleTick(now time.Time)
- func (this *ControlHandle) HandleWake()
- type EContrlState
- type EEvtFireMode
- type EMSCMode
- type EServiceState
- type GoComponent
- type GoState
- type GoTask
- type GoTaskPool
- type GoTimer
- func (this *GoTimer) DayerHandler(after0 time.Duration, tickFun TimerHandFunc, right ...bool)
- func (this *GoTimer) Init() *GoTimer
- func (this *GoTimer) TickTimer()
- func (this *GoTimer) TimerHandler(d time.Duration, tickFun TimerHandFunc, right ...bool)
- func (this *GoTimer) UnTimHandler(tickFun func() bool)
- type Gore
- type IControler
- type ICtrlHandler
- type ICtrlOwner
- type IDebuger
- type IGoTimer
- type IMsger
- type ISeriHandler
- type ISeriOwner
- type IServicer
- type ISettinger
- type MCMsgHandFunc
- type ServiceHandle
- type StateHandFunc
- type StateHandler
- type SvieFunc
- type TCmdId
- type TCtrlId
- type TEventId
- type TMsgId
- type TSvieId
- type Task
- type TaskHandFunc
- type TaskHandler
- type TaskOwn
- type TimerHandFunc
Constants ¶
const ( DEF_SERVICE_BEGIN_ID TSvieId = 0 // 服务ID起始ID[0是无效ID] DEF_CONTROL_BEGIN_ID TCtrlId = 0 // 控制ID起始ID[0是无效ID] DEF_CONTROL_MSIZE = 50 // 系统控制器数量默认初始值 DEF_CONTROL_MID_MSIZE = 50 // 系统控制器消息数量默认初始值 DEF_SERVICE_MSIZE = 20 // 系统服务数量默认初始化值 DEF_SETTING_MSIZE = 10 // 系统配置数量默认初始化值 DEF_SERVICE_RATE = 30 // 服务默认更新频率 DEF_SERVICE_CAPY = 300 // 服务CAST通道的默认大小 DEF_CONTROL_RATE = 10 // 控制器更新频率 DEF_CONTROL_CAPY = 250 // 控制器通道的默认大小 DEF_SETLOAD_RATE = 30 // 配置热更新检测频率 DEF_SETT_RELOAD_GAP = 60 // 配置热更新检测间隔(s) DEF_EVENT_HANDLE_MSIZE = 25 // 全局事件绑定函数类型默认初始化数量 DEF_TASK_CAPY_SIZE = 50 // GoTask默认容量 DEF_TASK_POOL_SIZE = 2 // GoTaskPool默认大小 DEF_TASK_EXIT_TIME_OUT = 3 * time.Second // task退出超时 DEF_TASK_WARN_TIME_OUT = 3 * time.Second // task处理超时告警日志 )
Common Consts
Variables ¶
var ( ErrTimeOut = errors.New("TimeOut") ErrExitNormal = errors.New("NormalExit") ErrBusyTimeOut = errors.New("BusyTimeOut") ErrServiceStart = errors.New("ServiceStartError") ErrServiceState = errors.New("ServiceStateState") ErrServiceParam = errors.New("ServiceStateParam") ErrServiceNotUse = errors.New("ServiceNotUse") ErrServiceNotFound = errors.New("ServiceNotFound") ErrServiceExisted = errors.New("ServiceExisted") ErrServiceNoCmd = errors.New("ServiceCmdNotFound") ErrServiceCmdHandleNil = errors.New("ServiceCmdHandleNil") ErrServiceDoneFunNil = errors.New("ServiceCallDoneFunIsNil") ErrServiceCallRetNot2 = errors.New("ServiceCallNot2Ret") ErrServiceCallRetType = errors.New("ServiceCallRetType") ErrSvieEventParams = errors.New("ServiceEventParams") ErrSvieEventExisted = errors.New("ServiceEventExisted") ErrSvieEventNoExist = errors.New("ServiceEventNoExist") ErrSvieEventHandleNil = errors.New("ServiceEventHandleNil") ErrSvieEventHandleRepeat = errors.New("ServiceEventHandleRepeat") ErrSvieEventHandleNoMatch = errors.New("ServiceEventHandleNoMatch") ErrControlNotRunning = errors.New("ControlNotRunning") ErrSettingNoReload = errors.New("SettingNoReload") )
----------------------------------------------------------------------------- =================================常量定义===================================== ----------------------------------------------------------------------------- Common Errors
var MCGoreDef = Gore{0, DEF_CONTROL_CAPY}
内置 CtrlGore
var MCGoreHig = Gore{DEF_CONTROL_RATE * 2, DEF_CONTROL_CAPY * 2}
var MCGoreLow = Gore{DEF_CONTROL_RATE / 2, DEF_CONTROL_CAPY}
var MSGoreDef = Gore{DEF_SERVICE_RATE, DEF_SERVICE_CAPY}
内置 SeriGore
var MSGoreHig = Gore{DEF_SERVICE_RATE * 2, DEF_SERVICE_CAPY * 2}
var MSGoreLow = Gore{DEF_SERVICE_RATE / 2, DEF_SERVICE_CAPY}
Functions ¶
func Caly ¶
func Caly(des TSvieId, cmd TCmdId, args []interface{}, from IServicer, done CalyHandFunc)
同步调用服务上的方法[des:目标服务 cmd:命令函数ID args:命令的参数 from:关注的服务 done:调用完后回调函数]
func Cast ¶
----------------------------------------------------------------------------- ==================================Logical==================================== ----------------------------------------------------------------------------- 异步调用服务上的方法[des:目标服务 cmd:命令函数ID args:命令的参数]
func EventServiceCountFor ¶
C风格-有多少个服务监听了des服务的特定事件
func GetCtrlMsgName ¶
func InitSettings ¶
func InitSettings()
----------------------------------------------------------------------------- ==================================Internal=================================== -----------------------------------------------------------------------------
func Load ¶
func Load(name string, handle ISettinger) error
func SetCtrlMsgName ¶
func SettingContent ¶
func SettingCount ¶
func SettingCount() int
func SettingOverview ¶
func SettingOverview() string
Types ¶
type ControlHandle ¶
type ControlHandle struct {
ICtrlOwner // 用继承的方式又有嵌入之意。
}
----------------------------------------------------------------------------- ===============================默认空控制定义================================== -----------------------------------------------------------------------------
func (*ControlHandle) HandleGore ¶
func (this *ControlHandle) HandleGore() *Gore
func (*ControlHandle) HandleInit ¶
func (this *ControlHandle) HandleInit(own ICtrlOwner)
func (*ControlHandle) HandleLaun ¶
func (this *ControlHandle) HandleLaun()
func (*ControlHandle) HandleStat ¶
func (this *ControlHandle) HandleStat() string
func (*ControlHandle) HandleSusp ¶
func (this *ControlHandle) HandleSusp()
func (*ControlHandle) HandleTerm ¶
func (this *ControlHandle) HandleTerm()
func (*ControlHandle) HandleTick ¶
func (this *ControlHandle) HandleTick(now time.Time)
func (*ControlHandle) HandleWake ¶
func (this *ControlHandle) HandleWake()
type EContrlState ¶
type EContrlState int32 //
=> 控制器运行状态
const ( ECS_Declare EContrlState = iota ECS_Initing ECS_Suspend // 不影响命令的执行 ECS_Running ECS_Closeup )
func (EContrlState) String ¶
func (e EContrlState) String() string
type EEvtFireMode ¶
type EEvtFireMode int //
事件发射模式
const ( EEFM_CAST EEvtFireMode = iota // 不用等待 EEFM_CALL // 同步等待 EEFM_CASY // 异步等待 )
func (EEvtFireMode) String ¶
func (e EEvtFireMode) String() string
type EServiceState ¶
type EServiceState int32 //
=> 服务运行状态
const ( ESS_Stopped EServiceState = iota ESS_Initing ESS_Suspend // 不影响命令的执行 ESS_Running ESS_Exiting )
func (EServiceState) String ¶
func (e EServiceState) String() string
type GoComponent ¶
type GoComponent struct { }
------------------------------------------------------------------------------ =================================GoComponent================================== ------------------------------------------------------------------------------
type GoState ¶
type GoState struct {
// contains filtered or unexported fields
}
func (*GoState) Add ¶
func (this *GoState) Add(state int, handle StateHandler)
func (*GoState) AddFun ¶
func (this *GoState) AddFun(state int, handle StateHandFunc)
type GoTask ¶
type GoTask struct {
// contains filtered or unexported fields
}
func (*GoTask) HandleFunc ¶
func (this *GoTask) HandleFunc(handler TaskHandFunc)
func (*GoTask) Handler ¶
func (this *GoTask) Handler(handler TaskHandler)
type GoTaskPool ¶
type GoTaskPool struct {
// contains filtered or unexported fields
}
func NewGoTaskPool ¶
func NewGoTaskPool(name string, psize, capy int) *GoTaskPool
------------------------------------------------------------------------------ ==================================GoTaskPool================================== ------------------------------------------------------------------------------
func (*GoTaskPool) Exit ¶
func (this *GoTaskPool) Exit()
func (*GoTaskPool) HandleFunc ¶
func (this *GoTaskPool) HandleFunc(handler TaskHandFunc)
func (*GoTaskPool) Handler ¶
func (this *GoTaskPool) Handler(handler TaskHandler)
func (*GoTaskPool) Init ¶
func (this *GoTaskPool) Init(name string, psize, capy int) *GoTaskPool
func (*GoTaskPool) Post ¶
func (this *GoTaskPool) Post(task *Task)
type GoTimer ¶
type GoTimer struct {
// contains filtered or unexported fields
}
func (*GoTimer) DayerHandler ¶
func (this *GoTimer) DayerHandler(after0 time.Duration, tickFun TimerHandFunc, right ...bool)
func (*GoTimer) TimerHandler ¶
func (this *GoTimer) TimerHandler(d time.Duration, tickFun TimerHandFunc, right ...bool)
func (*GoTimer) UnTimHandler ¶
type IControler ¶
type IControler interface { // 线程ID[0:没启动loop] GoId() int // 控制器名称 Name() string // 控制器状态 State() EContrlState // 控制器ID CtrlId() TCtrlId // 控制器状况 Status() string // 线程暂停 ThreadSusp() error // 线程唤醒 ThreadWake() error // 投递消息 PostMsg(msg IMsger) error // contains filtered or unexported methods }
-------- Control开放接口
type ICtrlHandler ¶
type ICtrlHandler interface { // 控制器参数 - [--重--载--] 控制器初始化参数 [argv = nil 则使用默认值] HandleGore() *Gore // 控制器准备 - [基类->派生] 当控制器创建后调用 初始数据 HandleInit(own ICtrlOwner) // 控制器销毁 - [派生->基类] 当控制器销毁时调用 清理数据 HandleTerm() // 控制器首次 - [基类->派生] 当控制器运行时最先调用且调用一次 HandleLaun() // 控制器更新 - [基类->派生] 当控制器tick时调用 定时更新 HandleTick(now time.Time) // 控制器暂停 - [基类->派生] 当控制器被暂停时调用 HandleSusp() // 控制器恢复 - [基类->派生] 当控制器被恢复时调用 HandleWake() // 运行状况 - [基类->派生] 当调用Status时调用 建议JSON格式 HandleStat() string }
-------- Control代理接口
func Install ¶
func Install(id TCtrlId, handle ICtrlHandler) ICtrlHandler
----------------------------------------------------------------------------- ===================================Public==================================== ----------------------------------------------------------------------------- 安装一个全局控制器[init时安装,work时自动启动,如果重复安装则后者覆盖前者]
type ICtrlOwner ¶
type ICtrlOwner interface { // 继承接口 ILogMe // 继承接口 IGoTimer // 继承接口 IControler // 获取Handler Handler() ICtrlHandler // 注册消息处理函数 SetCMHandle(mid TMsgId, handle MCMsgHandFunc) // 获取主读写锁 Mutex() *sync.RWMutex // 控制器主写锁 WLock() interface{} WUnLock(i interface{}) // 控制器主读锁 RLock() interface{} RUnLock(i interface{}) }
-------- Control自主接口
type IDebuger ¶
----------------------------------------------------------------------------- ============================IDebuger调试器开关接口============================= -----------------------------------------------------------------------------
type IGoTimer ¶
type IGoTimer interface { // 添加定时器[当tickFun返回false时自动删除此TimerHandler] TimerHandler(d time.Duration, tickFun TimerHandFunc, right ...bool) // 添加每天一次的定时器[同上](after0:每天超过零点多少时间) DayerHandler(after0 time.Duration, tickFun TimerHandFunc, right ...bool) // 移除定时器 UnTimHandler(tickFun func() bool) }
type ISeriHandler ¶
type ISeriHandler interface { // 初始参数 - [重载--覆盖] 当返回!nil时初始化服务 否则禁用此服务 HandleGore() *Gore // 先初始化 - [基类->派生] 当此服务创建后调用 初始化数据 HandleInit(own ISeriOwner) // 首次运行 - [派生--基类] 当服务首次运行前调用一次 HandleLaun() // 服务更新 - [基类->派生] 当服务tick时调用 定时更新 HandleTick(now time.Time) // 服务销毁 - [派生->基类] 当服务销毁时调用 清理服务数据 HandleTerm(reason error) // 运行状态 - [基类->派生] 当调用Status时调用 推荐JSON格式 HandleStat() string }
-------- Service代理接口
func Regist ¶
func Regist(id TSvieId, handle ISeriHandler) ISeriHandler
----------------------------------------------------------------------------- ===================================Public==================================== ----------------------------------------------------------------------------- 注册一个服务[init时使用]
type ISeriOwner ¶
type ISeriOwner interface { // 继承接口 ILogMe // 继承接口 IGoTimer // 继承接口 IServicer // 获取Handler Handler() ISeriHandler // 设置Cast命令[Cast: handle(...); Call:handle(...)(data,err)] SetCmdHandler(handles ...interface{}) // 检测Cast命令有效性 HasCmdHandler(cmdId TCmdId) bool // 注册事件 RegisterEvent(eveSignal interface{}) // 注销事件 UnRegistEvent(eveSignal interface{}) // 触发此服务的某个事件[不用等待] 以[EEFM_CAST]的方式执行所有careHandle Trigger(eId TEventId, args ...interface{}) // 触发此服务的某个事件[同步等待] 以[EEFM_CALL]的方式执行所有careHandle Emitter(eId TEventId, args ...interface{}) // 触发此服务的某个事件[异步等待] 以[EEFM_CASY]的方式执行所有careHandle 当所有的careHandle执行完后回调doneFun Emitasy(eId TEventId, args []interface{}, doneFun func()) }
-------- Service自主接口
type IServicer ¶
type IServicer interface { // 获取此服务GoId[默认0] GoId() int // 获取此服务的名称 Name() string // 此服务运行状态 State() EServiceState // 获取此服务的ID SieId() TSvieId // 调用此服务命令[不用等待] (除非目标服务死了,否则一定会处理这个cast) Cast(cmdId TCmdId, args ...interface{}) // 调用此服务命令[同步等待] (目标服务繁忙:0.1s超时错误 目标服务空闲:1s等待结果超时错误且有可能返回超时最终其实是调用成功的) Call(cmdId TCmdId, args ...interface{}) (interface{}, error) // if call myself then gg... // 调用此服务命令[异步等待] (done不可为nil) // > from 为nil : 调用完成后将结果为参数执行done(CallRet) // > from 非nil : 调用完成后将结果为参数Cast到from服务在源服务中执行done(CallRet),此时如果from服务gg... Caly(cmdId TCmdId, args []interface{}, from IServicer, done CalyHandFunc) // 调用此服务的特定函数[自行调用] Exec(selfFun interface{}, args ...interface{}) // 监听此服务的某个事件 // > care 为空 : 当此事件触发时直接执行careHandle(...) // > care 非空 : 当此事件触发时根据触发类型以不同的方式来执行careHandle(...),方式见:EEvtFireMode Listen(eId TEventId, care IServicer, careHandle interface{}) error // 取消监听此服务的某个事件 UnListen(eId TEventId, care IServicer, careHandle interface{}) error // 停止此服务[自我调用是异步,其他调用是同步] Stop(reason error, wait bool) // 此服务运行时状况 Status() string }
-------- Service开放接口
type ISettinger ¶
type ISettinger interface { // 配置初加载 HandleInit() error // 配置名称 HandlePath() string // 配置内容 HandleContent() string // 配置热加载[自行保证线程安全] HandleReload() error }
----------------------------------------------------------------------------- ===========================ISettinger配置文件基本接口=========================== -----------------------------------------------------------------------------
func Preload ¶
func Preload(name string, handle ISettinger) ISettinger
----------------------------------------------------------------------------- ===================================Public==================================== -----------------------------------------------------------------------------
type MCMsgHandFunc ¶
type MCMsgHandFunc func(IMsger)
----------------------------------------------------------------------------- =================================Control接口================================== -----------------------------------------------------------------------------
type ServiceHandle ¶
type ServiceHandle struct {
ISeriOwner // 用继承的方式又有嵌入之意。
}
----------------------------------------------------------------------------- ===============================默认空服务定义================================== -----------------------------------------------------------------------------
func (*ServiceHandle) HandleGore ¶
func (this *ServiceHandle) HandleGore() *Gore
func (*ServiceHandle) HandleInit ¶
func (this *ServiceHandle) HandleInit(own ISeriOwner)
func (*ServiceHandle) HandleLaun ¶
func (this *ServiceHandle) HandleLaun()
func (*ServiceHandle) HandleStat ¶
func (this *ServiceHandle) HandleStat() string
func (*ServiceHandle) HandleTerm ¶
func (this *ServiceHandle) HandleTerm(reason error)
func (*ServiceHandle) HandleTick ¶
func (this *ServiceHandle) HandleTick(now time.Time)
type StateHandFunc ¶
type StateHandFunc func(enter bool)
func (StateHandFunc) OnHandleState ¶
func (f StateHandFunc) OnHandleState(enter bool)
type StateHandler ¶
type StateHandler interface {
OnHandleState(enter bool)
}
----------------------------------------------------------------------------- ===============================GoState Handler=============================== -----------------------------------------------------------------------------
type TMsgId ¶
type TMsgId int //
=> 控制器消息类型
type TaskHandFunc ¶
func (TaskHandFunc) OnHandleTask ¶
func (f TaskHandFunc) OnHandleTask(o *TaskOwn, param interface{}) (ret interface{}, err error)
type TaskHandler ¶
type TaskHandler interface {
OnHandleTask(o *TaskOwn, param interface{}) (ret interface{}, err error)
}
----------------------------------------------------------------------------- ===============================GoTask Handler================================ -----------------------------------------------------------------------------
type TimerHandFunc ¶
----------------------------------------------------------------------------- ===============================GoTimer开放接口================================ -----------------------------------------------------------------------------