mss

package
v0.0.0-...-d73eb14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2019 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

View Source
var MCGoreDef = Gore{0, DEF_CONTROL_CAPY}

内置 CtrlGore

内置 SeriGore

Functions

func Call

func Call(des TSvieId, cmd TCmdId, args ...interface{}) (interface{}, error)

同步调用服务上的方法[des:目标服务 cmd:命令函数ID args:命令的参数]

func Caly

func Caly(des TSvieId, cmd TCmdId, args []interface{}, from IServicer, done CalyHandFunc)

同步调用服务上的方法[des:目标服务 cmd:命令函数ID args:命令的参数 from:关注的服务 done:调用完后回调函数]

func Cast

func Cast(des TSvieId, cmd TCmdId, args ...interface{})

----------------------------------------------------------------------------- ==================================Logical==================================== ----------------------------------------------------------------------------- 异步调用服务上的方法[des:目标服务 cmd:命令函数ID args:命令的参数]

func CombStatus

func CombStatus(field, content string, first ...bool) string

-------- 组装状态数据

func ControlCount

func ControlCount() int

获得控制器总数

func CtrlOverview

func CtrlOverview() string

获得控制器信息概览

func EventCount

func EventCount(who IServicer) int

C风格-服务拥有多少个事件

func EventCountFor

func EventCountFor(des IServicer, care IServicer) int

C风格-care服务监听了des服务多少个事件

func EventOverview

func EventOverview(who IServicer) string

某服务的事件概览信息

func EventServiceCount

func EventServiceCount(des IServicer) int

C风格-有多少个服务监听了des服务的事件

func EventServiceCountFor

func EventServiceCountFor(des IServicer, eventId TEventId) int

C风格-有多少个服务监听了des服务的特定事件

func GetCtrlMsgName

func GetCtrlMsgName(id TMsgId) string

func GetCtrlName

func GetCtrlName(id TCtrlId) string

获取某个控制器的名字

func GetSvieName

func GetSvieName(sId TSvieId) string

获取某个服务的名字

func InitSettings

func InitSettings()

----------------------------------------------------------------------------- ==================================Internal=================================== -----------------------------------------------------------------------------

func Listen

func Listen(des TSvieId, desEvent TEventId, care IServicer, careHandle interface{}) error

注册服务上的事件[des:目标服务 desEvent:目标服务的事件 care:关注的服务 careHandle:关注的服务的函数]

func Load

func Load(name string, handle ISettinger) error

func ReLoad

func ReLoad(name string) error

func Run

func Run(delayfun func(), sett ...*SLogSetting)

=> 单函数入口

func ServiceCount

func ServiceCount() int

获得服务总数[all=false]

func SetCtrlMsgName

func SetCtrlMsgName(id TMsgId, name string)

func SetCtrlName

func SetCtrlName(id TCtrlId, name string)

给某个控制器设置名字

func SetSvieName

func SetSvieName(sId TSvieId, name string)

给某个服务设置名字

func SettingContent

func SettingContent(name string) string

func SettingCount

func SettingCount() int

func SettingOverview

func SettingOverview() string

func Shut

func Shut(reason error)

=> 停止所有服务[同步]

func Start

func Start(id TSvieId, handle ISeriHandler) error

启动一个服务[运行时使用]

func Stop

func Stop(id TSvieId, wait bool, reason error)

停止一个服务

func SvieOverview

func SvieOverview(wild ...bool) string

获得所有服务信息

func UnListen

func UnListen(des TSvieId, desEvent TEventId, care IServicer, careHandle interface{}) error

反注册服务上的事件[参数上同]

func Work

func Work() error

=> 运行所有服务

Types

type CalyHandFunc

type CalyHandFunc func(result interface{}, err error)

Caly回调函数签名

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 EMSCMode

type EMSCMode int //

=> ECallMode

const (
	ECM_CAST EMSCMode = iota // 同步等待
	ECM_CALL                 // 不用等待
)

func (EMSCMode) String

func (e EMSCMode) 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)

func (*GoState) Been

func (this *GoState) Been() TDurt

func (*GoState) Clr

func (this *GoState) Clr()

func (*GoState) Run

func (this *GoState) Run()

func (*GoState) Set

func (this *GoState) Set(state int)

func (*GoState) State

func (this *GoState) State() int

type GoTask

type GoTask struct {
	// contains filtered or unexported fields
}

func NewGoTask

func NewGoTask(name string, capy int, usrdat ...interface{}) *GoTask

func (*GoTask) Exit

func (this *GoTask) Exit()

func (*GoTask) HandleFunc

func (this *GoTask) HandleFunc(handler TaskHandFunc)

func (*GoTask) Handler

func (this *GoTask) Handler(handler TaskHandler)

func (*GoTask) Init

func (this *GoTask) Init(name string, capy int, usrdat ...interface{}) *GoTask

func (*GoTask) Post

func (this *GoTask) Post(task *Task)

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) Init

func (this *GoTimer) Init() *GoTimer

func (*GoTimer) TickTimer

func (this *GoTimer) TickTimer()

func (*GoTimer) TimerHandler

func (this *GoTimer) TimerHandler(d time.Duration, tickFun TimerHandFunc, right ...bool)

func (*GoTimer) UnTimHandler

func (this *GoTimer) UnTimHandler(tickFun func() bool)

type Gore

type Gore struct {
	Rate, Capy int
}

Go线程初始化参数结构

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开放接口

func GetContrler

func GetContrler(id TCtrlId) IControler

获得指定的控制器

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

type IDebuger interface {

	// 设置开关
	EnDebug(enable bool)

	// 是否开关
	IsDebug() bool
}

----------------------------------------------------------------------------- ============================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 IMsger

type IMsger interface {
	MsgId() TMsgId
}

-------- Control消息

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开放接口

func GetServicer

func GetServicer(sId TSvieId) IServicer

获得指定sId的IServicer

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 SvieFunc

type SvieFunc struct {
	Svie IServicer
	Func CalyHandFunc
}

微服务函数对象

type TCmdId

type TCmdId = string //

=> 服务命令

type TCtrlId

type TCtrlId int //

=> 控制器Id

func (TCtrlId) String

func (id TCtrlId) String() string

type TEventId

type TEventId = string //

=> 服务事件Id

type TMsgId

type TMsgId int //

=> 控制器消息类型

const (
	CTL_DEFAULT_ID  TMsgId = iota // 默认消息
	MCM_THREAD_SUSP               // 暂停消息
	MCM_THREAD_WAKE               // 恢复消息
	CTL_MSG_ID_END  TMsgId = 100
)

Contrl_Msg

func (TMsgId) MsgId

func (id TMsgId) MsgId() TMsgId

func (TMsgId) String

func (id TMsgId) String() string

type TSvieId

type TSvieId int //

=> 服务Id

func (TSvieId) String

func (id TSvieId) String() string

type Task

type Task struct {
	Param interface{}
	Donef *SvieFunc
}

Task请求结构

type TaskHandFunc

type TaskHandFunc func(*TaskOwn, interface{}) (ret interface{}, err error)

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 TaskOwn

type TaskOwn struct {
	GoId   int
	UsrDat interface{}
}

Task

type TimerHandFunc

type TimerHandFunc func(now time.Time) (keep bool)

----------------------------------------------------------------------------- ===============================GoTimer开放接口================================ -----------------------------------------------------------------------------

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL