mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-05 15:34:49 +08:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cf071a444 | ||
|
|
e6c09064bf | ||
|
|
84ab0cb84a | ||
|
|
22fe00173b | ||
|
|
8e0ed62fca | ||
|
|
7116b509e9 | ||
|
|
73d384361d | ||
|
|
ce56b19fe8 | ||
|
|
1367d776e6 | ||
|
|
987d35ff15 | ||
|
|
d225bb4bd2 | ||
|
|
ea37fb5081 | ||
|
|
0a92f48d0b | ||
|
|
f5e86fee02 | ||
|
|
166facc959 | ||
|
|
5bb747201b | ||
|
|
1014bc54e4 | ||
|
|
9c26c742fe | ||
|
|
d1935b1bbc | ||
|
|
90d54bf3e2 | ||
|
|
78cc33c84e | ||
|
|
9cf21bf418 | ||
|
|
c6d0bd9a19 | ||
|
|
61bf95e457 | ||
|
|
8b2a551ee5 | ||
|
|
927c2ffa37 | ||
|
|
b23b30aac5 |
123
README.md
123
README.md
@@ -661,51 +661,7 @@ Module1 Release.
|
||||
第四章:事件使用
|
||||
----------------
|
||||
|
||||
事件是origin中一个重要的组成部分,可以在同一个node中的service与service或者与module之间进行事件通知。系统内置的几个服务,如:TcpService/HttpService等都是通过事件功能实现。他也是一个典型的观察者设计模型。在event中有两个类型的interface,一个是event.IEventProcessor它提供注册与卸载功能,另一个是event.IEventHandler提供消息广播等功能。
|
||||
|
||||
在目录simple_event/TestService4.go中
|
||||
|
||||
```
|
||||
package simple_event
|
||||
|
||||
import (
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"github.com/duanhf2012/origin/v2/node"
|
||||
"github.com/duanhf2012/origin/v2/service"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
//自定义事件类型,必需从event.Sys_Event_User_Define开始
|
||||
//event.Sys_Event_User_Define以内给系统预留
|
||||
EVENT1 event.EventType =event.Sys_Event_User_Define+1
|
||||
)
|
||||
|
||||
func init(){
|
||||
node.Setup(&TestService4{})
|
||||
}
|
||||
|
||||
type TestService4 struct {
|
||||
service.Service
|
||||
}
|
||||
|
||||
func (slf *TestService4) OnInit() error {
|
||||
//10秒后触发广播事件
|
||||
slf.AfterFunc(time.Second*10,slf.TriggerEvent)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (slf *TestService4) TriggerEvent(){
|
||||
//广播事件,传入event.Event对象,类型为EVENT1,Data可以自定义任何数据
|
||||
//这样,所有监听者都可以收到该事件
|
||||
slf.GetEventHandler().NotifyEvent(&event.Event{
|
||||
Type: EVENT1,
|
||||
Data: "event data.",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
事件是origin中一个重要的组成部分,可以在服务与各module之间进行事件通知。它也是一个典型的观察者设计模型。在event中有两个类型的interface,一个是event.IEventProcessor它提供注册与卸载功能,另一个是event.IEventHandler提供消息广播等功能。
|
||||
|
||||
在目录simple_event/TestService5.go中
|
||||
|
||||
@@ -713,53 +669,68 @@ func (slf *TestService4) TriggerEvent(){
|
||||
package simple_event
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"github.com/duanhf2012/origin/v2/node"
|
||||
"github.com/duanhf2012/origin/v2/service"
|
||||
"fmt"
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"github.com/duanhf2012/origin/v2/node"
|
||||
"github.com/duanhf2012/origin/v2/service"
|
||||
"github.com/duanhf2012/origin/v2/util/timer"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init(){
|
||||
node.Setup(&TestService5{})
|
||||
func init() {
|
||||
node.Setup(&TestService5{})
|
||||
}
|
||||
|
||||
const (
|
||||
//自定义事件类型,必需从event.Sys_Event_User_Define开始
|
||||
//event.Sys_Event_User_Define以内给系统预留
|
||||
EVENT1 event.EventType = event.Sys_Event_User_Define + 1
|
||||
)
|
||||
|
||||
type TestService5 struct {
|
||||
service.Service
|
||||
service.Service
|
||||
}
|
||||
|
||||
type TestModule struct {
|
||||
service.Module
|
||||
service.Module
|
||||
}
|
||||
|
||||
func (slf *TestModule) OnInit() error{
|
||||
//在当前node中查找TestService4
|
||||
pService := node.GetService("TestService4")
|
||||
func (slf *TestModule) OnInit() error {
|
||||
//在TestModule中注册监听EVENT1事件
|
||||
slf.GetEventProcessor().RegEventReceiverFunc(EVENT1, slf.GetEventHandler(), slf.OnModuleEvent)
|
||||
|
||||
//在TestModule中,往TestService4中注册EVENT1类型事件监听
|
||||
pService.(*TestService4).GetEventProcessor().RegEventReciverFunc(EVENT1,slf.GetEventHandler(),slf.OnModuleEvent)
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (slf *TestModule) OnModuleEvent(ev event.IEvent){
|
||||
event := ev.(*event.Event)
|
||||
fmt.Printf("OnModuleEvent type :%d data:%+v\n",event.GetEventType(),event.Data)
|
||||
// OnModuleEvent 模块监听事件回调
|
||||
func (slf *TestModule) OnModuleEvent(ev event.IEvent) {
|
||||
event := ev.(*event.Event)
|
||||
fmt.Printf("OnModuleEvent type :%d data:%+v\n", event.GetEventType(), event.Data)
|
||||
}
|
||||
|
||||
|
||||
//服务初始化函数,在安装服务时,服务将自动调用OnInit函数
|
||||
// OnInit 服务初始化函数,在安装服务时,服务将自动调用OnInit函数
|
||||
func (slf *TestService5) OnInit() error {
|
||||
//通过服务名获取服务对象
|
||||
pService := node.GetService("TestService4")
|
||||
//在服务中注册监听EVENT1类型事件
|
||||
slf.RegEventReceiverFunc(EVENT1, slf.GetEventHandler(), slf.OnServiceEvent)
|
||||
slf.AddModule(&TestModule{})
|
||||
|
||||
////在TestModule中,往TestService4中注册EVENT1类型事件监听
|
||||
pService.(*TestService4).GetEventProcessor().RegEventReciverFunc(EVENT1,slf.GetEventHandler(),slf.OnServiceEvent)
|
||||
slf.AddModule(&TestModule{})
|
||||
return nil
|
||||
slf.AfterFunc(time.Second*10, slf.TriggerEvent)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (slf *TestService5) OnServiceEvent(ev event.IEvent){
|
||||
event := ev.(*event.Event)
|
||||
fmt.Printf("OnServiceEvent type :%d data:%+v\n",event.Type,event.Data)
|
||||
// OnServiceEvent 服务监听事件回调
|
||||
func (slf *TestService5) OnServiceEvent(ev event.IEvent) {
|
||||
event := ev.(*event.Event)
|
||||
fmt.Printf("OnServiceEvent type :%d data:%+v\n", event.Type, event.Data)
|
||||
}
|
||||
|
||||
func (slf *TestService5) TriggerEvent(t *timer.Timer) {
|
||||
//广播事件,传入event.Event对象,类型为EVENT1,Data可以自定义任何数据
|
||||
//这样,所有监听者都可以收到该事件
|
||||
slf.GetEventHandler().NotifyEvent(&event.Event{
|
||||
Type: EVENT1,
|
||||
Data: "event data.",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -768,8 +739,8 @@ func (slf *TestService5) OnServiceEvent(ev event.IEvent){
|
||||
程序运行10秒后,调用slf.TriggerEvent函数广播事件,于是在TestService5中会收到
|
||||
|
||||
```
|
||||
OnServiceEvent type :1001 data:event data.
|
||||
OnModuleEvent type :1001 data:event data.
|
||||
OnServiceEvent type :2 data:event data.
|
||||
OnModuleEvent type :2 data:event data.
|
||||
```
|
||||
|
||||
在上面的TestModule中监听的事情,当这个Module被Release时监听会自动卸载。
|
||||
@@ -1181,6 +1152,8 @@ func (slf *TestTcpService) OnRequest (clientid string,msg proto.Message){
|
||||
* log/log.go:日志的封装,可以使用它构建对象记录业务文件日志
|
||||
* util:在该目录下,有常用的uuid,hash,md5,协程封装等工具库
|
||||
* https://github.com/duanhf2012/originservice: 其他扩展支持的服务可以在该工程上看到,目前支持firebase推送的封装。
|
||||
* https://github.com/duanhf2012/origingame: 基础游戏服务器的框架
|
||||
* etcd与nats开发环境搭建可以从https://github.com/duanhf2012/originserver_v2下的docker-compose获取
|
||||
|
||||
备注:
|
||||
-----
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"errors"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
var configDir = "./config/"
|
||||
@@ -62,6 +64,7 @@ type Cluster struct {
|
||||
locker sync.RWMutex //结点与服务关系保护锁
|
||||
mapRpc map[string]*NodeRpcInfo //nodeId
|
||||
mapServiceNode map[string]map[string]struct{} //map[serviceName]map[NodeId]
|
||||
mapTemplateServiceNode map[string]map[string]struct{} //map[templateServiceName]map[serviceName]nodeId
|
||||
|
||||
callSet rpc.CallSet
|
||||
rpcNats rpc.RpcNats
|
||||
@@ -137,6 +140,20 @@ func (cls *Cluster) delServiceNode(serviceName string, nodeId string) {
|
||||
return
|
||||
}
|
||||
|
||||
//处理模板服务
|
||||
splitServiceName := strings.Split(serviceName,":")
|
||||
if len(splitServiceName) == 2 {
|
||||
serviceName = splitServiceName[0]
|
||||
templateServiceName := splitServiceName[1]
|
||||
|
||||
mapService := cls.mapTemplateServiceNode[templateServiceName]
|
||||
delete(mapService,serviceName)
|
||||
|
||||
if len(cls.mapTemplateServiceNode[templateServiceName]) == 0 {
|
||||
delete(cls.mapTemplateServiceNode,templateServiceName)
|
||||
}
|
||||
}
|
||||
|
||||
mapNode := cls.mapServiceNode[serviceName]
|
||||
delete(mapNode, nodeId)
|
||||
if len(mapNode) == 0 {
|
||||
@@ -171,7 +188,20 @@ func (cls *Cluster) serviceDiscoverySetNodeInfo(nodeInfo *NodeInfo) {
|
||||
continue
|
||||
}
|
||||
mapDuplicate[serviceName] = nil
|
||||
if _, ok := cls.mapServiceNode[serviceName]; ok == false {
|
||||
|
||||
//如果是模板服务,则记录模板关系
|
||||
splitServiceName := strings.Split(serviceName,":")
|
||||
if len(splitServiceName) == 2 {
|
||||
serviceName = splitServiceName[0]
|
||||
templateServiceName := splitServiceName[1]
|
||||
//记录模板
|
||||
if _, ok = cls.mapTemplateServiceNode[templateServiceName]; ok == false {
|
||||
cls.mapTemplateServiceNode[templateServiceName]=map[string]struct{}{}
|
||||
}
|
||||
cls.mapTemplateServiceNode[templateServiceName][serviceName] = struct{}{}
|
||||
}
|
||||
|
||||
if _, ok = cls.mapServiceNode[serviceName]; ok == false {
|
||||
cls.mapServiceNode[serviceName] = make(map[string]struct{}, 1)
|
||||
}
|
||||
cls.mapServiceNode[serviceName][nodeInfo.NodeId] = struct{}{}
|
||||
@@ -259,25 +289,29 @@ func (cls *Cluster) GetRpcClient(nodeId string) (*rpc.Client,bool) {
|
||||
return cls.getRpcClient(nodeId)
|
||||
}
|
||||
|
||||
func GetRpcClient(nodeId string, serviceMethod string,filterRetire bool, clientList []*rpc.Client) (error, int) {
|
||||
func GetNodeIdByTemplateService(templateServiceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client) {
|
||||
return GetCluster().GetNodeIdByTemplateService(templateServiceName, rpcClientList, filterRetire)
|
||||
}
|
||||
|
||||
func GetRpcClient(nodeId string, serviceMethod string,filterRetire bool, clientList []*rpc.Client) (error, []*rpc.Client) {
|
||||
if nodeId != rpc.NodeIdNull {
|
||||
pClient,retire := GetCluster().GetRpcClient(nodeId)
|
||||
if pClient == nil {
|
||||
return fmt.Errorf("cannot find nodeid %d!", nodeId), 0
|
||||
return fmt.Errorf("cannot find nodeid %s", nodeId), nil
|
||||
}
|
||||
|
||||
//如果需要筛选掉退休结点
|
||||
if filterRetire == true && retire == true {
|
||||
return fmt.Errorf("cannot find nodeid %d!", nodeId), 0
|
||||
return fmt.Errorf("cannot find nodeid %s", nodeId), nil
|
||||
}
|
||||
|
||||
clientList[0] = pClient
|
||||
return nil, 1
|
||||
clientList = append(clientList,pClient)
|
||||
return nil, clientList
|
||||
}
|
||||
|
||||
findIndex := strings.Index(serviceMethod, ".")
|
||||
if findIndex == -1 {
|
||||
return fmt.Errorf("servicemethod param %s is error!", serviceMethod), 0
|
||||
return fmt.Errorf("servicemethod param %s is error!", serviceMethod), nil
|
||||
}
|
||||
serviceName := serviceMethod[:findIndex]
|
||||
|
||||
@@ -376,10 +410,50 @@ func GetNodeByServiceName(serviceName string) map[string]struct{} {
|
||||
return mapNodeId
|
||||
}
|
||||
|
||||
// GetNodeByTemplateServiceName 通过模板服务名获取服务名,返回 map[serviceName真实服务名]NodeId
|
||||
func GetNodeByTemplateServiceName(templateServiceName string) map[string]string {
|
||||
cluster.locker.RLock()
|
||||
defer cluster.locker.RUnlock()
|
||||
|
||||
mapServiceName := cluster.mapTemplateServiceNode[templateServiceName]
|
||||
mapNodeId := make(map[string]string,9)
|
||||
for serviceName := range mapServiceName {
|
||||
mapNode, ok := cluster.mapServiceNode[serviceName]
|
||||
if ok == false {
|
||||
return nil
|
||||
}
|
||||
|
||||
for nodeId,_ := range mapNode {
|
||||
mapNodeId[serviceName] = nodeId
|
||||
}
|
||||
}
|
||||
|
||||
return mapNodeId
|
||||
}
|
||||
|
||||
func (cls *Cluster) GetGlobalCfg() interface{} {
|
||||
return cls.globalCfg
|
||||
}
|
||||
|
||||
|
||||
func (cls *Cluster) ParseGlobalCfg(cfg interface{}) error{
|
||||
if cls.globalCfg == nil {
|
||||
return errors.New("no service configuration found")
|
||||
}
|
||||
|
||||
rv := reflect.ValueOf(cls.globalCfg)
|
||||
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||
return errors.New("no service configuration found")
|
||||
}
|
||||
|
||||
bytes,err := json.Marshal(cls.globalCfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal(bytes,cfg)
|
||||
}
|
||||
|
||||
func (cls *Cluster) GetNodeInfo(nodeId string) (NodeInfo,bool) {
|
||||
cls.locker.RLock()
|
||||
defer cls.locker.RUnlock()
|
||||
@@ -392,19 +466,24 @@ func (cls *Cluster) GetNodeInfo(nodeId string) (NodeInfo,bool) {
|
||||
return nodeInfo.nodeInfo,true
|
||||
}
|
||||
|
||||
func (dc *Cluster) CanDiscoveryService(fromMasterNodeId string,serviceName string) bool{
|
||||
func (cls *Cluster) CanDiscoveryService(fromMasterNodeId string,serviceName string) bool{
|
||||
canDiscovery := true
|
||||
|
||||
for i:=0;i<len(dc.GetLocalNodeInfo().DiscoveryService);i++{
|
||||
masterNodeId := dc.GetLocalNodeInfo().DiscoveryService[i].MasterNodeId
|
||||
splitServiceName := strings.Split(serviceName,":")
|
||||
if len(splitServiceName) == 2 {
|
||||
serviceName = splitServiceName[0]
|
||||
}
|
||||
|
||||
for i:=0;i<len(cls.GetLocalNodeInfo().DiscoveryService);i++{
|
||||
masterNodeId := cls.GetLocalNodeInfo().DiscoveryService[i].MasterNodeId
|
||||
//无效的配置,则跳过
|
||||
if masterNodeId == rpc.NodeIdNull && len(dc.GetLocalNodeInfo().DiscoveryService[i].ServiceList)==0 {
|
||||
if masterNodeId == rpc.NodeIdNull && len(cls.GetLocalNodeInfo().DiscoveryService[i].ServiceList)==0 {
|
||||
continue
|
||||
}
|
||||
|
||||
canDiscovery = false
|
||||
if masterNodeId == fromMasterNodeId || masterNodeId == rpc.NodeIdNull {
|
||||
for _,discoveryService := range dc.GetLocalNodeInfo().DiscoveryService[i].ServiceList {
|
||||
for _,discoveryService := range cls.GetLocalNodeInfo().DiscoveryService[i].ServiceList {
|
||||
if discoveryService == serviceName {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -160,6 +160,12 @@ func (dc *OriginDiscoveryMaster) OnNatsDisconnect(){
|
||||
}
|
||||
|
||||
func (ds *OriginDiscoveryMaster) OnNodeConnected(nodeId string) {
|
||||
var notifyDiscover rpc.SubscribeDiscoverNotify
|
||||
notifyDiscover.IsFull = true
|
||||
notifyDiscover.NodeInfo = ds.nodeInfo
|
||||
notifyDiscover.MasterNodeId = cluster.GetLocalNodeInfo().NodeId
|
||||
|
||||
ds.GoNode(nodeId, SubServiceDiscover, ¬ifyDiscover)
|
||||
}
|
||||
|
||||
func (ds *OriginDiscoveryMaster) OnNodeDisconnect(nodeId string) {
|
||||
@@ -183,6 +189,10 @@ func (ds *OriginDiscoveryMaster) OnNodeDisconnect(nodeId string) {
|
||||
|
||||
func (ds *OriginDiscoveryMaster) RpcCastGo(serviceMethod string, args interface{}) {
|
||||
for nodeId, _ := range ds.mapNodeInfo {
|
||||
if nodeId == cluster.GetLocalNodeInfo().NodeId {
|
||||
continue
|
||||
}
|
||||
|
||||
ds.GoNode(nodeId, serviceMethod, args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ func (cls *Cluster) readLocalClusterConfig(nodeId string) (DiscoveryInfo, []Node
|
||||
}
|
||||
|
||||
if nodeId != rpc.NodeIdNull && (len(nodeInfoList) != 1) {
|
||||
return discoveryInfo, nil,rpcMode, fmt.Errorf("%d configurations were found for the configuration with node ID %d!", len(nodeInfoList), nodeId)
|
||||
return discoveryInfo, nil,rpcMode, fmt.Errorf("nodeid %s configuration error in NodeList", nodeId)
|
||||
}
|
||||
|
||||
for i, _ := range nodeInfoList {
|
||||
@@ -325,6 +325,10 @@ func (cls *Cluster) readLocalService(localNodeId string) error {
|
||||
//保存公共配置
|
||||
for _, s := range cls.localNodeInfo.ServiceList {
|
||||
for {
|
||||
splitServiceName := strings.Split(s,":")
|
||||
if len(splitServiceName) == 2 {
|
||||
s = splitServiceName[0]
|
||||
}
|
||||
//取公共服务配置
|
||||
pubCfg, ok := serviceConfig[s]
|
||||
if ok == true {
|
||||
@@ -355,6 +359,11 @@ func (cls *Cluster) readLocalService(localNodeId string) error {
|
||||
|
||||
//组合所有的配置
|
||||
for _, s := range cls.localNodeInfo.ServiceList {
|
||||
splitServiceName := strings.Split(s,":")
|
||||
if len(splitServiceName) == 2 {
|
||||
s = splitServiceName[0]
|
||||
}
|
||||
|
||||
//先从NodeService中找
|
||||
var serviceCfg interface{}
|
||||
var ok bool
|
||||
@@ -382,12 +391,24 @@ func (cls *Cluster) parseLocalCfg() {
|
||||
|
||||
cls.mapRpc[cls.localNodeInfo.NodeId] = &rpcInfo
|
||||
|
||||
for _, sName := range cls.localNodeInfo.ServiceList {
|
||||
if _, ok := cls.mapServiceNode[sName]; ok == false {
|
||||
cls.mapServiceNode[sName] = make(map[string]struct{})
|
||||
for _, serviceName := range cls.localNodeInfo.ServiceList {
|
||||
splitServiceName := strings.Split(serviceName,":")
|
||||
if len(splitServiceName) == 2 {
|
||||
serviceName = splitServiceName[0]
|
||||
templateServiceName := splitServiceName[1]
|
||||
//记录模板
|
||||
if _, ok := cls.mapTemplateServiceNode[templateServiceName]; ok == false {
|
||||
cls.mapTemplateServiceNode[templateServiceName]=map[string]struct{}{}
|
||||
}
|
||||
cls.mapTemplateServiceNode[templateServiceName][serviceName] = struct{}{}
|
||||
}
|
||||
|
||||
cls.mapServiceNode[sName][cls.localNodeInfo.NodeId] = struct{}{}
|
||||
|
||||
if _, ok := cls.mapServiceNode[serviceName]; ok == false {
|
||||
cls.mapServiceNode[serviceName] = make(map[string]struct{})
|
||||
}
|
||||
|
||||
cls.mapServiceNode[serviceName][cls.localNodeInfo.NodeId] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,6 +424,7 @@ func (cls *Cluster) InitCfg(localNodeId string) error {
|
||||
cls.localServiceCfg = map[string]interface{}{}
|
||||
cls.mapRpc = map[string]*NodeRpcInfo{}
|
||||
cls.mapServiceNode = map[string]map[string]struct{}{}
|
||||
cls.mapTemplateServiceNode = map[string]map[string]struct{}{}
|
||||
|
||||
//加载本地结点的NodeList配置
|
||||
discoveryInfo, nodeInfoList,rpcMode, err := cls.readLocalClusterConfig(localNodeId)
|
||||
@@ -436,12 +458,37 @@ func (cls *Cluster) IsConfigService(serviceName string) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
func (cls *Cluster) GetNodeIdByTemplateService(templateServiceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client) {
|
||||
cls.locker.RLock()
|
||||
defer cls.locker.RUnlock()
|
||||
|
||||
func (cls *Cluster) GetNodeIdByService(serviceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, int) {
|
||||
mapServiceName := cls.mapTemplateServiceNode[templateServiceName]
|
||||
for serviceName := range mapServiceName {
|
||||
mapNodeId, ok := cls.mapServiceNode[serviceName]
|
||||
if ok == true {
|
||||
for nodeId, _ := range mapNodeId {
|
||||
pClient,retire := GetCluster().getRpcClient(nodeId)
|
||||
if pClient == nil || pClient.IsConnected() == false {
|
||||
continue
|
||||
}
|
||||
|
||||
//如果需要筛选掉退休的,对retire状态的结点略过
|
||||
if filterRetire == true && retire == true {
|
||||
continue
|
||||
}
|
||||
|
||||
rpcClientList = append(rpcClientList,pClient)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, rpcClientList
|
||||
}
|
||||
|
||||
func (cls *Cluster) GetNodeIdByService(serviceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client) {
|
||||
cls.locker.RLock()
|
||||
defer cls.locker.RUnlock()
|
||||
mapNodeId, ok := cls.mapServiceNode[serviceName]
|
||||
count := 0
|
||||
if ok == true {
|
||||
for nodeId, _ := range mapNodeId {
|
||||
pClient,retire := GetCluster().getRpcClient(nodeId)
|
||||
@@ -454,15 +501,11 @@ func (cls *Cluster) GetNodeIdByService(serviceName string, rpcClientList []*rpc.
|
||||
continue
|
||||
}
|
||||
|
||||
rpcClientList[count] = pClient
|
||||
count++
|
||||
if count >= cap(rpcClientList) {
|
||||
break
|
||||
}
|
||||
rpcClientList = append(rpcClientList,pClient)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, count
|
||||
return nil, rpcClientList
|
||||
}
|
||||
|
||||
func (cls *Cluster) GetServiceCfg(serviceName string) interface{} {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/duanhf2012/origin/v2/log"
|
||||
"github.com/duanhf2012/origin/v2/util/queue"
|
||||
"context"
|
||||
)
|
||||
|
||||
var idleTimeout = int64(2 * time.Second)
|
||||
@@ -30,6 +31,9 @@ type dispatch struct {
|
||||
|
||||
waitWorker sync.WaitGroup
|
||||
waitDispatch sync.WaitGroup
|
||||
|
||||
cancelContext context.Context
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func (d *dispatch) open(minGoroutineNum int32, maxGoroutineNum int32, tasks chan task, cbChannel chan func(error)) {
|
||||
@@ -40,7 +44,7 @@ func (d *dispatch) open(minGoroutineNum int32, maxGoroutineNum int32, tasks chan
|
||||
d.workerQueue = make(chan task)
|
||||
d.cbChannel = cbChannel
|
||||
d.queueIdChannel = make(chan int64, cap(tasks))
|
||||
|
||||
d.cancelContext,d.cancel = context.WithCancel(context.Background())
|
||||
d.waitDispatch.Add(1)
|
||||
go d.run()
|
||||
}
|
||||
@@ -64,10 +68,12 @@ func (d *dispatch) run() {
|
||||
d.processqueueEvent(queueId)
|
||||
case <-timeout.C:
|
||||
d.processTimer()
|
||||
if atomic.LoadInt32(&d.minConcurrentNum) == -1 && len(d.tasks) == 0 {
|
||||
atomic.StoreInt64(&idleTimeout,int64(time.Millisecond * 10))
|
||||
}
|
||||
case <- d.cancelContext.Done():
|
||||
atomic.StoreInt64(&idleTimeout,int64(time.Millisecond * 5))
|
||||
timeout.Reset(time.Duration(atomic.LoadInt64(&idleTimeout)))
|
||||
for i:=int32(0);i<d.workerNum;i++{
|
||||
d.processIdle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +172,8 @@ func (c *dispatch) pushAsyncDoCallbackEvent(cb func(err error)) {
|
||||
|
||||
func (d *dispatch) close() {
|
||||
atomic.StoreInt32(&d.minConcurrentNum, -1)
|
||||
d.cancel()
|
||||
|
||||
|
||||
breakFor:
|
||||
for {
|
||||
|
||||
@@ -17,6 +17,8 @@ const (
|
||||
Sys_Event_QueueTaskFinish EventType = -10
|
||||
Sys_Event_Retire EventType = -11
|
||||
Sys_Event_EtcdDiscovery EventType = -12
|
||||
Sys_Event_Gin_Event EventType = -13
|
||||
Sys_Event_FrameTick EventType = -14
|
||||
|
||||
Sys_Event_User_Define EventType = 1
|
||||
)
|
||||
|
||||
@@ -10,16 +10,20 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
const defaultSkip = 7
|
||||
type IOriginHandler interface {
|
||||
slog.Handler
|
||||
Lock()
|
||||
UnLock()
|
||||
SetSkip(skip int)
|
||||
GetSkip() int
|
||||
}
|
||||
|
||||
type BaseHandler struct {
|
||||
addSource bool
|
||||
w io.Writer
|
||||
locker sync.Mutex
|
||||
skip int
|
||||
}
|
||||
|
||||
type OriginTextHandler struct {
|
||||
@@ -32,6 +36,14 @@ type OriginJsonHandler struct {
|
||||
*slog.JSONHandler
|
||||
}
|
||||
|
||||
func (bh *BaseHandler) SetSkip(skip int){
|
||||
bh.skip = skip
|
||||
}
|
||||
|
||||
func (bh *BaseHandler) GetSkip() int{
|
||||
return bh.skip
|
||||
}
|
||||
|
||||
func getStrLevel(level slog.Level) string{
|
||||
switch level {
|
||||
case LevelTrace:
|
||||
@@ -78,6 +90,7 @@ func NewOriginTextHandler(level slog.Level,w io.Writer,addSource bool,replaceAtt
|
||||
ReplaceAttr: replaceAttr,
|
||||
})
|
||||
|
||||
textHandler.skip = defaultSkip
|
||||
return &textHandler
|
||||
}
|
||||
|
||||
@@ -124,6 +137,7 @@ func NewOriginJsonHandler(level slog.Level,w io.Writer,addSource bool,replaceAtt
|
||||
ReplaceAttr: replaceAttr,
|
||||
})
|
||||
|
||||
jsonHandler.skip = defaultSkip
|
||||
return &jsonHandler
|
||||
}
|
||||
|
||||
@@ -141,7 +155,7 @@ func (oh *OriginJsonHandler) Handle(context context.Context, record slog.Record)
|
||||
func (b *BaseHandler) Fill(context context.Context, record *slog.Record) {
|
||||
if b.addSource {
|
||||
var pcs [1]uintptr
|
||||
runtime.Callers(7, pcs[:])
|
||||
runtime.Callers(b.skip, pcs[:])
|
||||
record.PC = pcs[0]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,6 +239,10 @@ func (iw *IoWriter) swichFile() error{
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetDefaultHandler() IOriginHandler{
|
||||
return gLogger.(*Logger).Slogger.Handler().(IOriginHandler)
|
||||
}
|
||||
|
||||
func NewTextLogger(level slog.Level,pathName string,filePrefix string,addSource bool,logChannelCap int) (ILogger,error){
|
||||
var logger Logger
|
||||
logger.ioWriter.filePath = pathName
|
||||
|
||||
@@ -45,8 +45,10 @@ func (jsonProcessor *JsonProcessor) SetByteOrder(littleEndian bool) {
|
||||
}
|
||||
|
||||
// must goroutine safe
|
||||
func (jsonProcessor *JsonProcessor ) MsgRoute(clientId string,msg interface{}) error{
|
||||
func (jsonProcessor *JsonProcessor ) MsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte)) error{
|
||||
pPackInfo := msg.(*JsonPackInfo)
|
||||
defer recyclerReaderBytes(pPackInfo.rawMsg)
|
||||
|
||||
v,ok := jsonProcessor.mapMsg[pPackInfo.typ]
|
||||
if ok == false {
|
||||
return fmt.Errorf("cannot find msgtype %d is register!",pPackInfo.typ)
|
||||
@@ -58,7 +60,6 @@ func (jsonProcessor *JsonProcessor ) MsgRoute(clientId string,msg interface{}) e
|
||||
|
||||
func (jsonProcessor *JsonProcessor) Unmarshal(clientId string,data []byte) (interface{}, error) {
|
||||
typeStruct := struct {Type int `json:"typ"`}{}
|
||||
defer jsonProcessor.ReleaseBytes(data)
|
||||
err := json.Unmarshal(data, &typeStruct)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -76,7 +77,7 @@ func (jsonProcessor *JsonProcessor) Unmarshal(clientId string,data []byte) (inte
|
||||
return nil,err
|
||||
}
|
||||
|
||||
return &JsonPackInfo{typ:msgType,msg:msgData},nil
|
||||
return &JsonPackInfo{typ:msgType,msg:msgData,rawMsg: data},nil
|
||||
}
|
||||
|
||||
func (jsonProcessor *JsonProcessor) Marshal(clientId string,msg interface{}) ([]byte, error) {
|
||||
@@ -104,7 +105,8 @@ func (jsonProcessor *JsonProcessor) MakeRawMsg(msgType uint16,msg []byte) *JsonP
|
||||
return &JsonPackInfo{typ:msgType,rawMsg:msg}
|
||||
}
|
||||
|
||||
func (jsonProcessor *JsonProcessor) UnknownMsgRoute(clientId string,msg interface{}){
|
||||
func (jsonProcessor *JsonProcessor) UnknownMsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte)){
|
||||
defer recyclerReaderBytes(msg.([]byte))
|
||||
if jsonProcessor.unknownMessageHandler==nil {
|
||||
log.Debug("Unknown message",log.String("clientId",clientId))
|
||||
return
|
||||
|
||||
@@ -54,8 +54,10 @@ func (slf *PBPackInfo) GetMsg() proto.Message {
|
||||
}
|
||||
|
||||
// must goroutine safe
|
||||
func (pbProcessor *PBProcessor) MsgRoute(clientId string, msg interface{}) error {
|
||||
func (pbProcessor *PBProcessor) MsgRoute(clientId string, msg interface{},recyclerReaderBytes func(data []byte)) error {
|
||||
pPackInfo := msg.(*PBPackInfo)
|
||||
defer recyclerReaderBytes(pPackInfo.rawMsg)
|
||||
|
||||
v, ok := pbProcessor.mapMsg[pPackInfo.typ]
|
||||
if ok == false {
|
||||
return fmt.Errorf("Cannot find msgtype %d is register!", pPackInfo.typ)
|
||||
@@ -67,7 +69,6 @@ func (pbProcessor *PBProcessor) MsgRoute(clientId string, msg interface{}) error
|
||||
|
||||
// must goroutine safe
|
||||
func (pbProcessor *PBProcessor) Unmarshal(clientId string, data []byte) (interface{}, error) {
|
||||
defer pbProcessor.ReleaseBytes(data)
|
||||
return pbProcessor.UnmarshalWithOutRelease(clientId, data)
|
||||
}
|
||||
|
||||
@@ -91,7 +92,7 @@ func (pbProcessor *PBProcessor) UnmarshalWithOutRelease(clientId string, data []
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &PBPackInfo{typ: msgType, msg: protoMsg}, nil
|
||||
return &PBPackInfo{typ: msgType, msg: protoMsg,rawMsg:data}, nil
|
||||
}
|
||||
|
||||
// must goroutine safe
|
||||
@@ -133,8 +134,9 @@ func (pbProcessor *PBProcessor) MakeRawMsg(msgType uint16, msg []byte) *PBPackIn
|
||||
return &PBPackInfo{typ: msgType, rawMsg: msg}
|
||||
}
|
||||
|
||||
func (pbProcessor *PBProcessor) UnknownMsgRoute(clientId string, msg interface{}) {
|
||||
func (pbProcessor *PBProcessor) UnknownMsgRoute(clientId string, msg interface{},recyclerReaderBytes func(data []byte)) {
|
||||
pbProcessor.unknownMessageHandler(clientId, msg.([]byte))
|
||||
recyclerReaderBytes(msg.([]byte))
|
||||
}
|
||||
|
||||
// connect event
|
||||
|
||||
@@ -38,9 +38,11 @@ func (pbRawProcessor *PBRawProcessor) SetByteOrder(littleEndian bool) {
|
||||
}
|
||||
|
||||
// must goroutine safe
|
||||
func (pbRawProcessor *PBRawProcessor ) MsgRoute(clientId string, msg interface{}) error{
|
||||
func (pbRawProcessor *PBRawProcessor ) MsgRoute(clientId string, msg interface{},recyclerReaderBytes func(data []byte)) error{
|
||||
pPackInfo := msg.(*PBRawPackInfo)
|
||||
pbRawProcessor.msgHandler(clientId,pPackInfo.typ,pPackInfo.rawMsg)
|
||||
recyclerReaderBytes(pPackInfo.rawMsg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -80,7 +82,8 @@ func (pbRawProcessor *PBRawProcessor) MakeRawMsg(msgType uint16,msg []byte,pbRaw
|
||||
pbRawPackInfo.rawMsg = msg
|
||||
}
|
||||
|
||||
func (pbRawProcessor *PBRawProcessor) UnknownMsgRoute(clientId string,msg interface{}){
|
||||
func (pbRawProcessor *PBRawProcessor) UnknownMsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte)){
|
||||
defer recyclerReaderBytes(msg.([]byte))
|
||||
if pbRawProcessor.unknownMessageHandler == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package processor
|
||||
|
||||
type IProcessor interface {
|
||||
// must goroutine safe
|
||||
MsgRoute(clientId string,msg interface{}) error
|
||||
MsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte)) error
|
||||
//must goroutine safe
|
||||
UnknownMsgRoute(clientId string,msg interface{})
|
||||
UnknownMsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte))
|
||||
// connect event
|
||||
ConnectedRoute(clientId string)
|
||||
DisConnectedRoute(clientId string)
|
||||
|
||||
@@ -129,6 +129,13 @@ func (tcpConn *TCPConn) ReadMsg() ([]byte, error) {
|
||||
return tcpConn.msgParser.Read(tcpConn)
|
||||
}
|
||||
|
||||
func (tcpConn *TCPConn) GetRecyclerReaderBytes() func (data []byte) {
|
||||
bytePool := tcpConn.msgParser.IBytesMempool
|
||||
return func(data []byte) {
|
||||
bytePool.ReleaseBytes(data)
|
||||
}
|
||||
}
|
||||
|
||||
func (tcpConn *TCPConn) ReleaseReadMsg(byteBuff []byte){
|
||||
tcpConn.msgParser.ReleaseBytes(byteBuff)
|
||||
}
|
||||
|
||||
50
node/node.go
50
node/node.go
@@ -25,9 +25,11 @@ import (
|
||||
var sig chan os.Signal
|
||||
var nodeId string
|
||||
var preSetupService []service.IService //预安装
|
||||
var preSetupTemplateService []func()service.IService
|
||||
var profilerInterval time.Duration
|
||||
var bValid bool
|
||||
var configDir = "./config/"
|
||||
var NodeIsRun = false
|
||||
|
||||
const(
|
||||
SingleStop syscall.Signal = 10
|
||||
@@ -56,7 +58,7 @@ func init() {
|
||||
console.RegisterCommandString("loglevel", "debug", "<-loglevel debug|release|warning|error|fatal> Set loglevel.", setLevel)
|
||||
console.RegisterCommandString("logpath", "", "<-logpath path> Set log file path.", setLogPath)
|
||||
console.RegisterCommandInt("logsize", 0, "<-logsize size> Set log size(MB).", setLogSize)
|
||||
console.RegisterCommandInt("logchannelcap", 0, "<-logchannelcap num> Set log channel cap.", setLogChannelCapNum)
|
||||
console.RegisterCommandInt("logchannelcap", -1, "<-logchannelcap num> Set log channel cap.", setLogChannelCapNum)
|
||||
console.RegisterCommandString("pprof", "", "<-pprof ip:port> Open performance analysis.", setPprof)
|
||||
}
|
||||
|
||||
@@ -169,6 +171,31 @@ func initNode(id string) {
|
||||
serviceOrder := cluster.GetCluster().GetLocalNodeInfo().ServiceList
|
||||
for _,serviceName:= range serviceOrder{
|
||||
bSetup := false
|
||||
|
||||
//判断是否有配置模板服务
|
||||
splitServiceName := strings.Split(serviceName,":")
|
||||
if len(splitServiceName) == 2 {
|
||||
serviceName = splitServiceName[0]
|
||||
templateServiceName := splitServiceName[1]
|
||||
for _,newSer := range preSetupTemplateService {
|
||||
ser := newSer()
|
||||
ser.OnSetup(ser)
|
||||
if ser.GetName() == templateServiceName {
|
||||
ser.SetName(serviceName)
|
||||
ser.Init(ser,cluster.GetRpcClient,cluster.GetRpcServer,cluster.GetCluster().GetServiceCfg(ser.GetName()))
|
||||
service.Setup(ser)
|
||||
|
||||
bSetup = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if bSetup == false{
|
||||
log.Error("Template service not found",log.String("service name",serviceName),log.String("template service name",templateServiceName))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range preSetupService {
|
||||
if s.GetName() != serviceName {
|
||||
continue
|
||||
@@ -301,13 +328,13 @@ func startNode(args interface{}) error {
|
||||
myName, mErr := sysprocess.GetMyProcessName()
|
||||
//当前进程名获取失败,不应该发生
|
||||
if mErr != nil {
|
||||
log.SInfo("get my process's name is error,", mErr.Error())
|
||||
log.Info("get my process's name is error",log.ErrorAttr("err", mErr))
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
//进程id存在,而且进程名也相同,被认为是当前进程重复运行
|
||||
if cErr == nil && name == myName {
|
||||
log.SInfo(fmt.Sprintf("repeat runs are not allowed,node is %s,processid is %d",strNodeId,processId))
|
||||
log.Info("repeat runs are not allowed",log.String("nodeId",strNodeId),log.Int("processId",processId))
|
||||
os.Exit(-1)
|
||||
}
|
||||
break
|
||||
@@ -328,13 +355,14 @@ func startNode(args interface{}) error {
|
||||
cluster.GetCluster().Start()
|
||||
|
||||
//6.监听程序退出信号&性能报告
|
||||
bRun := true
|
||||
|
||||
var pProfilerTicker *time.Ticker = &time.Ticker{}
|
||||
if profilerInterval > 0 {
|
||||
pProfilerTicker = time.NewTicker(profilerInterval)
|
||||
}
|
||||
|
||||
for bRun {
|
||||
NodeIsRun = true
|
||||
for NodeIsRun {
|
||||
select {
|
||||
case s := <-sig:
|
||||
signal := s.(syscall.Signal)
|
||||
@@ -342,7 +370,7 @@ func startNode(args interface{}) error {
|
||||
log.Info("receipt retire signal.")
|
||||
notifyAllServiceRetire()
|
||||
}else {
|
||||
bRun = false
|
||||
NodeIsRun = false
|
||||
log.Info("receipt stop signal.")
|
||||
}
|
||||
case <-pProfilerTicker.C:
|
||||
@@ -367,6 +395,12 @@ func Setup(s ...service.IService) {
|
||||
}
|
||||
}
|
||||
|
||||
func SetupTemplate(fs ...func()service.IService){
|
||||
for _, f := range fs {
|
||||
preSetupTemplateService = append(preSetupTemplateService, f)
|
||||
}
|
||||
}
|
||||
|
||||
func GetService(serviceName string) service.IService {
|
||||
return service.GetService(serviceName)
|
||||
}
|
||||
@@ -472,6 +506,10 @@ func setLogChannelCapNum(args interface{}) error {
|
||||
return errors.New("param logsize is error")
|
||||
}
|
||||
|
||||
if logChannelCap == -1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.LogChannelCap = logChannelCap
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -145,14 +145,12 @@ func DefaultReportFunction(name string,callNum int,costTime time.Duration,record
|
||||
return
|
||||
}
|
||||
|
||||
var strReport string
|
||||
strReport = "Profiler report tag "+name+":\n"
|
||||
var average int64
|
||||
if callNum>0 {
|
||||
average = costTime.Milliseconds()/int64(callNum)
|
||||
}
|
||||
|
||||
strReport += fmt.Sprintf("process count %d,take time %d Milliseconds,average %d Milliseconds/per.\n",callNum,costTime.Milliseconds(),average)
|
||||
log.Info("Profiler report tag "+name,log.Int("process count",callNum),log.Int64("take time",costTime.Milliseconds()),log.Int64("average",average))
|
||||
elem := record.Front()
|
||||
var strTypes string
|
||||
for elem!=nil {
|
||||
@@ -163,11 +161,9 @@ func DefaultReportFunction(name string,callNum int,costTime time.Duration,record
|
||||
strTypes = "slow process"
|
||||
}
|
||||
|
||||
strReport += fmt.Sprintf("%s:%s is take %d Milliseconds\n",strTypes,pRecord.RecordName,pRecord.CostTime.Milliseconds())
|
||||
log.Info("Profiler report type",log.String("Types",strTypes),log.String("RecordName",pRecord.RecordName),log.Int64("take time",pRecord.CostTime.Milliseconds()))
|
||||
elem = elem.Next()
|
||||
}
|
||||
|
||||
log.SInfo("report",strReport)
|
||||
}
|
||||
|
||||
func Report() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.31.0
|
||||
// protoc v3.11.4
|
||||
// source: test/rpc/messagequeue.proto
|
||||
// protoc v4.24.0
|
||||
// source: rpcproto/messagequeue.proto
|
||||
|
||||
package rpc
|
||||
|
||||
@@ -50,11 +50,11 @@ func (x SubscribeType) String() string {
|
||||
}
|
||||
|
||||
func (SubscribeType) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_test_rpc_messagequeue_proto_enumTypes[0].Descriptor()
|
||||
return file_rpcproto_messagequeue_proto_enumTypes[0].Descriptor()
|
||||
}
|
||||
|
||||
func (SubscribeType) Type() protoreflect.EnumType {
|
||||
return &file_test_rpc_messagequeue_proto_enumTypes[0]
|
||||
return &file_rpcproto_messagequeue_proto_enumTypes[0]
|
||||
}
|
||||
|
||||
func (x SubscribeType) Number() protoreflect.EnumNumber {
|
||||
@@ -63,7 +63,7 @@ func (x SubscribeType) Number() protoreflect.EnumNumber {
|
||||
|
||||
// Deprecated: Use SubscribeType.Descriptor instead.
|
||||
func (SubscribeType) EnumDescriptor() ([]byte, []int) {
|
||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{0}
|
||||
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
type SubscribeMethod int32
|
||||
@@ -96,11 +96,11 @@ func (x SubscribeMethod) String() string {
|
||||
}
|
||||
|
||||
func (SubscribeMethod) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_test_rpc_messagequeue_proto_enumTypes[1].Descriptor()
|
||||
return file_rpcproto_messagequeue_proto_enumTypes[1].Descriptor()
|
||||
}
|
||||
|
||||
func (SubscribeMethod) Type() protoreflect.EnumType {
|
||||
return &file_test_rpc_messagequeue_proto_enumTypes[1]
|
||||
return &file_rpcproto_messagequeue_proto_enumTypes[1]
|
||||
}
|
||||
|
||||
func (x SubscribeMethod) Number() protoreflect.EnumNumber {
|
||||
@@ -109,7 +109,7 @@ func (x SubscribeMethod) Number() protoreflect.EnumNumber {
|
||||
|
||||
// Deprecated: Use SubscribeMethod.Descriptor instead.
|
||||
func (SubscribeMethod) EnumDescriptor() ([]byte, []int) {
|
||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{1}
|
||||
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
type DBQueuePopReq struct {
|
||||
@@ -127,7 +127,7 @@ type DBQueuePopReq struct {
|
||||
func (x *DBQueuePopReq) Reset() {
|
||||
*x = DBQueuePopReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[0]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (x *DBQueuePopReq) String() string {
|
||||
func (*DBQueuePopReq) ProtoMessage() {}
|
||||
|
||||
func (x *DBQueuePopReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[0]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -153,7 +153,7 @@ func (x *DBQueuePopReq) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use DBQueuePopReq.ProtoReflect.Descriptor instead.
|
||||
func (*DBQueuePopReq) Descriptor() ([]byte, []int) {
|
||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{0}
|
||||
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *DBQueuePopReq) GetCustomerId() string {
|
||||
@@ -203,7 +203,7 @@ type DBQueuePopRes struct {
|
||||
func (x *DBQueuePopRes) Reset() {
|
||||
*x = DBQueuePopRes{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[1]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -216,7 +216,7 @@ func (x *DBQueuePopRes) String() string {
|
||||
func (*DBQueuePopRes) ProtoMessage() {}
|
||||
|
||||
func (x *DBQueuePopRes) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[1]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -229,7 +229,7 @@ func (x *DBQueuePopRes) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use DBQueuePopRes.ProtoReflect.Descriptor instead.
|
||||
func (*DBQueuePopRes) Descriptor() ([]byte, []int) {
|
||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{1}
|
||||
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *DBQueuePopRes) GetQueueName() string {
|
||||
@@ -255,7 +255,7 @@ type DBQueueSubscribeReq struct {
|
||||
SubType SubscribeType `protobuf:"varint,1,opt,name=SubType,proto3,enum=SubscribeType" json:"SubType,omitempty"` //订阅类型
|
||||
Method SubscribeMethod `protobuf:"varint,2,opt,name=Method,proto3,enum=SubscribeMethod" json:"Method,omitempty"` //订阅方法
|
||||
CustomerId string `protobuf:"bytes,3,opt,name=CustomerId,proto3" json:"CustomerId,omitempty"` //消费者Id
|
||||
FromNodeId int32 `protobuf:"varint,4,opt,name=FromNodeId,proto3" json:"FromNodeId,omitempty"`
|
||||
FromNodeId string `protobuf:"bytes,4,opt,name=FromNodeId,proto3" json:"FromNodeId,omitempty"`
|
||||
RpcMethod string `protobuf:"bytes,5,opt,name=RpcMethod,proto3" json:"RpcMethod,omitempty"`
|
||||
TopicName string `protobuf:"bytes,6,opt,name=TopicName,proto3" json:"TopicName,omitempty"` //主题名称
|
||||
StartIndex uint64 `protobuf:"varint,7,opt,name=StartIndex,proto3" json:"StartIndex,omitempty"` //开始位置 ,格式前4位是时间戳秒,后面是序号。如果填0时,服务自动修改成:(4bit 当前时间秒)| (0000 4bit)
|
||||
@@ -265,7 +265,7 @@ type DBQueueSubscribeReq struct {
|
||||
func (x *DBQueueSubscribeReq) Reset() {
|
||||
*x = DBQueueSubscribeReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[2]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func (x *DBQueueSubscribeReq) String() string {
|
||||
func (*DBQueueSubscribeReq) ProtoMessage() {}
|
||||
|
||||
func (x *DBQueueSubscribeReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[2]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[2]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -291,7 +291,7 @@ func (x *DBQueueSubscribeReq) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use DBQueueSubscribeReq.ProtoReflect.Descriptor instead.
|
||||
func (*DBQueueSubscribeReq) Descriptor() ([]byte, []int) {
|
||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{2}
|
||||
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *DBQueueSubscribeReq) GetSubType() SubscribeType {
|
||||
@@ -315,11 +315,11 @@ func (x *DBQueueSubscribeReq) GetCustomerId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *DBQueueSubscribeReq) GetFromNodeId() int32 {
|
||||
func (x *DBQueueSubscribeReq) GetFromNodeId() string {
|
||||
if x != nil {
|
||||
return x.FromNodeId
|
||||
}
|
||||
return 0
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *DBQueueSubscribeReq) GetRpcMethod() string {
|
||||
@@ -359,7 +359,7 @@ type DBQueueSubscribeRes struct {
|
||||
func (x *DBQueueSubscribeRes) Reset() {
|
||||
*x = DBQueueSubscribeRes{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[3]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -372,7 +372,7 @@ func (x *DBQueueSubscribeRes) String() string {
|
||||
func (*DBQueueSubscribeRes) ProtoMessage() {}
|
||||
|
||||
func (x *DBQueueSubscribeRes) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[3]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[3]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -385,7 +385,7 @@ func (x *DBQueueSubscribeRes) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use DBQueueSubscribeRes.ProtoReflect.Descriptor instead.
|
||||
func (*DBQueueSubscribeRes) Descriptor() ([]byte, []int) {
|
||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{3}
|
||||
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
type DBQueuePublishReq struct {
|
||||
@@ -400,7 +400,7 @@ type DBQueuePublishReq struct {
|
||||
func (x *DBQueuePublishReq) Reset() {
|
||||
*x = DBQueuePublishReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[4]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -413,7 +413,7 @@ func (x *DBQueuePublishReq) String() string {
|
||||
func (*DBQueuePublishReq) ProtoMessage() {}
|
||||
|
||||
func (x *DBQueuePublishReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[4]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[4]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -426,7 +426,7 @@ func (x *DBQueuePublishReq) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use DBQueuePublishReq.ProtoReflect.Descriptor instead.
|
||||
func (*DBQueuePublishReq) Descriptor() ([]byte, []int) {
|
||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{4}
|
||||
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *DBQueuePublishReq) GetTopicName() string {
|
||||
@@ -452,7 +452,7 @@ type DBQueuePublishRes struct {
|
||||
func (x *DBQueuePublishRes) Reset() {
|
||||
*x = DBQueuePublishRes{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[5]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -465,7 +465,7 @@ func (x *DBQueuePublishRes) String() string {
|
||||
func (*DBQueuePublishRes) ProtoMessage() {}
|
||||
|
||||
func (x *DBQueuePublishRes) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[5]
|
||||
mi := &file_rpcproto_messagequeue_proto_msgTypes[5]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -478,13 +478,13 @@ func (x *DBQueuePublishRes) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use DBQueuePublishRes.ProtoReflect.Descriptor instead.
|
||||
func (*DBQueuePublishRes) Descriptor() ([]byte, []int) {
|
||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{5}
|
||||
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
var File_test_rpc_messagequeue_proto protoreflect.FileDescriptor
|
||||
var File_rpcproto_messagequeue_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_test_rpc_messagequeue_proto_rawDesc = []byte{
|
||||
0x0a, 0x1b, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
||||
var file_rpcproto_messagequeue_proto_rawDesc = []byte{
|
||||
0x0a, 0x1b, 0x72, 0x70, 0x63, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
||||
0x67, 0x65, 0x71, 0x75, 0x65, 0x75, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa3, 0x01,
|
||||
0x0a, 0x0d, 0x44, 0x42, 0x51, 0x75, 0x65, 0x75, 0x65, 0x50, 0x6f, 0x70, 0x52, 0x65, 0x71, 0x12,
|
||||
0x1e, 0x0a, 0x0a, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20,
|
||||
@@ -510,7 +510,7 @@ var file_test_rpc_messagequeue_proto_rawDesc = []byte{
|
||||
0x6f, 0x64, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x43, 0x75,
|
||||
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
|
||||
0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x46, 0x72,
|
||||
0x6f, 0x6d, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a,
|
||||
0x6f, 0x6d, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
|
||||
0x46, 0x72, 0x6f, 0x6d, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x52, 0x70,
|
||||
0x63, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x52,
|
||||
0x70, 0x63, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x6f, 0x70, 0x69,
|
||||
@@ -539,20 +539,20 @@ var file_test_rpc_messagequeue_proto_rawDesc = []byte{
|
||||
}
|
||||
|
||||
var (
|
||||
file_test_rpc_messagequeue_proto_rawDescOnce sync.Once
|
||||
file_test_rpc_messagequeue_proto_rawDescData = file_test_rpc_messagequeue_proto_rawDesc
|
||||
file_rpcproto_messagequeue_proto_rawDescOnce sync.Once
|
||||
file_rpcproto_messagequeue_proto_rawDescData = file_rpcproto_messagequeue_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_test_rpc_messagequeue_proto_rawDescGZIP() []byte {
|
||||
file_test_rpc_messagequeue_proto_rawDescOnce.Do(func() {
|
||||
file_test_rpc_messagequeue_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_rpc_messagequeue_proto_rawDescData)
|
||||
func file_rpcproto_messagequeue_proto_rawDescGZIP() []byte {
|
||||
file_rpcproto_messagequeue_proto_rawDescOnce.Do(func() {
|
||||
file_rpcproto_messagequeue_proto_rawDescData = protoimpl.X.CompressGZIP(file_rpcproto_messagequeue_proto_rawDescData)
|
||||
})
|
||||
return file_test_rpc_messagequeue_proto_rawDescData
|
||||
return file_rpcproto_messagequeue_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_test_rpc_messagequeue_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
|
||||
var file_test_rpc_messagequeue_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||
var file_test_rpc_messagequeue_proto_goTypes = []interface{}{
|
||||
var file_rpcproto_messagequeue_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
|
||||
var file_rpcproto_messagequeue_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||
var file_rpcproto_messagequeue_proto_goTypes = []interface{}{
|
||||
(SubscribeType)(0), // 0: SubscribeType
|
||||
(SubscribeMethod)(0), // 1: SubscribeMethod
|
||||
(*DBQueuePopReq)(nil), // 2: DBQueuePopReq
|
||||
@@ -562,7 +562,7 @@ var file_test_rpc_messagequeue_proto_goTypes = []interface{}{
|
||||
(*DBQueuePublishReq)(nil), // 6: DBQueuePublishReq
|
||||
(*DBQueuePublishRes)(nil), // 7: DBQueuePublishRes
|
||||
}
|
||||
var file_test_rpc_messagequeue_proto_depIdxs = []int32{
|
||||
var file_rpcproto_messagequeue_proto_depIdxs = []int32{
|
||||
0, // 0: DBQueueSubscribeReq.SubType:type_name -> SubscribeType
|
||||
1, // 1: DBQueueSubscribeReq.Method:type_name -> SubscribeMethod
|
||||
2, // [2:2] is the sub-list for method output_type
|
||||
@@ -572,13 +572,13 @@ var file_test_rpc_messagequeue_proto_depIdxs = []int32{
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_test_rpc_messagequeue_proto_init() }
|
||||
func file_test_rpc_messagequeue_proto_init() {
|
||||
if File_test_rpc_messagequeue_proto != nil {
|
||||
func init() { file_rpcproto_messagequeue_proto_init() }
|
||||
func file_rpcproto_messagequeue_proto_init() {
|
||||
if File_rpcproto_messagequeue_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_test_rpc_messagequeue_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_rpcproto_messagequeue_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*DBQueuePopReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -590,7 +590,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_test_rpc_messagequeue_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_rpcproto_messagequeue_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*DBQueuePopRes); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -602,7 +602,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_test_rpc_messagequeue_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_rpcproto_messagequeue_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*DBQueueSubscribeReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -614,7 +614,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_test_rpc_messagequeue_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_rpcproto_messagequeue_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*DBQueueSubscribeRes); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -626,7 +626,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_test_rpc_messagequeue_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_rpcproto_messagequeue_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*DBQueuePublishReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -638,7 +638,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_test_rpc_messagequeue_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_rpcproto_messagequeue_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*DBQueuePublishRes); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -655,19 +655,19 @@ func file_test_rpc_messagequeue_proto_init() {
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_test_rpc_messagequeue_proto_rawDesc,
|
||||
RawDescriptor: file_rpcproto_messagequeue_proto_rawDesc,
|
||||
NumEnums: 2,
|
||||
NumMessages: 6,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_test_rpc_messagequeue_proto_goTypes,
|
||||
DependencyIndexes: file_test_rpc_messagequeue_proto_depIdxs,
|
||||
EnumInfos: file_test_rpc_messagequeue_proto_enumTypes,
|
||||
MessageInfos: file_test_rpc_messagequeue_proto_msgTypes,
|
||||
GoTypes: file_rpcproto_messagequeue_proto_goTypes,
|
||||
DependencyIndexes: file_rpcproto_messagequeue_proto_depIdxs,
|
||||
EnumInfos: file_rpcproto_messagequeue_proto_enumTypes,
|
||||
MessageInfos: file_rpcproto_messagequeue_proto_msgTypes,
|
||||
}.Build()
|
||||
File_test_rpc_messagequeue_proto = out.File
|
||||
file_test_rpc_messagequeue_proto_rawDesc = nil
|
||||
file_test_rpc_messagequeue_proto_goTypes = nil
|
||||
file_test_rpc_messagequeue_proto_depIdxs = nil
|
||||
File_rpcproto_messagequeue_proto = out.File
|
||||
file_rpcproto_messagequeue_proto_rawDesc = nil
|
||||
file_rpcproto_messagequeue_proto_goTypes = nil
|
||||
file_rpcproto_messagequeue_proto_depIdxs = nil
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ message DBQueueSubscribeReq {
|
||||
SubscribeType SubType = 1; //订阅类型
|
||||
SubscribeMethod Method = 2; //订阅方法
|
||||
string CustomerId = 3; //消费者Id
|
||||
int32 FromNodeId = 4;
|
||||
string FromNodeId = 4;
|
||||
string RpcMethod = 5;
|
||||
string TopicName = 6; //主题名称
|
||||
uint64 StartIndex = 7; //开始位置 ,格式前4位是时间戳秒,后面是序号。如果填0时,服务自动修改成:(4bit 当前时间秒)| (0000 4bit)
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const maxClusterNode int = 128
|
||||
const maxClusterNode int = 32
|
||||
|
||||
type FuncRpcClient func(nodeId string, serviceMethod string,filterRetire bool, client []*Client) (error, int)
|
||||
type FuncRpcClient func(nodeId string, serviceMethod string,filterRetire bool, client []*Client) (error, []*Client)
|
||||
type FuncRpcServer func() IServer
|
||||
const NodeIdNull = ""
|
||||
|
||||
@@ -63,7 +63,7 @@ type RpcHandler struct {
|
||||
funcRpcClient FuncRpcClient
|
||||
funcRpcServer FuncRpcServer
|
||||
|
||||
pClientList []*Client
|
||||
//pClientList []*Client
|
||||
}
|
||||
|
||||
//type TriggerRpcConnEvent func(bConnect bool, clientSeq uint32, nodeId string)
|
||||
@@ -110,7 +110,6 @@ type IRpcHandler interface {
|
||||
GoNode(nodeId string, serviceMethod string, args interface{}) error
|
||||
RawGoNode(rpcProcessorType RpcProcessorType, nodeId string, rpcMethodId uint32, serviceName string, rawArgs []byte) error
|
||||
CastGo(serviceMethod string, args interface{}) error
|
||||
IsSingleCoroutine() bool
|
||||
UnmarshalInParam(rpcProcessor IRpcProcessor, serviceMethod string, rawRpcMethodId uint32, inParam []byte) (interface{}, error)
|
||||
GetRpcServer() FuncRpcServer
|
||||
}
|
||||
@@ -135,7 +134,6 @@ func (handler *RpcHandler) InitRpcHandler(rpcHandler IRpcHandler, getClientFun F
|
||||
handler.mapFunctions = map[string]RpcMethodInfo{}
|
||||
handler.funcRpcClient = getClientFun
|
||||
handler.funcRpcServer = getServerFun
|
||||
handler.pClientList = make([]*Client, maxClusterNode)
|
||||
handler.RegisterRpc(rpcHandler)
|
||||
}
|
||||
|
||||
@@ -274,7 +272,7 @@ func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
|
||||
//普通的rpc请求
|
||||
v, ok := handler.mapFunctions[request.RpcRequestData.GetServiceMethod()]
|
||||
if ok == false {
|
||||
err := "RpcHandler " + handler.rpcHandler.GetName() + "cannot find " + request.RpcRequestData.GetServiceMethod()
|
||||
err := "RpcHandler " + handler.rpcHandler.GetName() + " cannot find " + request.RpcRequestData.GetServiceMethod()
|
||||
log.Error("HandlerRpcRequest cannot find serviceMethod",log.String("RpcHandlerName",handler.rpcHandler.GetName()),log.String("serviceMethod",request.RpcRequestData.GetServiceMethod()))
|
||||
if request.requestHandle != nil {
|
||||
request.requestHandle(nil, RpcError(err))
|
||||
@@ -435,9 +433,9 @@ func (handler *RpcHandler) CallMethod(client *Client,ServiceMethod string, param
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId string, serviceMethod string, args interface{}) error {
|
||||
var pClientList [maxClusterNode]*Client
|
||||
err, count := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
||||
if count == 0 {
|
||||
pClientList :=make([]*Client,0,maxClusterNode)
|
||||
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList)
|
||||
if len(pClientList) == 0 {
|
||||
if err != nil {
|
||||
log.Error("call serviceMethod is failed",log.String("serviceMethod",serviceMethod),log.ErrorAttr("error",err))
|
||||
} else {
|
||||
@@ -446,13 +444,13 @@ func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId str
|
||||
return err
|
||||
}
|
||||
|
||||
if count > 1 && bCast == false {
|
||||
if len(pClientList) > 1 && bCast == false {
|
||||
log.Error("cannot call serviceMethod more then 1 node",log.String("serviceMethod",serviceMethod))
|
||||
return errors.New("cannot call more then 1 node")
|
||||
}
|
||||
|
||||
//2.rpcClient调用
|
||||
for i := 0; i < count; i++ {
|
||||
for i := 0; i < len(pClientList); i++ {
|
||||
pCall := pClientList[i].Go(pClientList[i].GetTargetNodeId(),DefaultRpcTimeout,handler.rpcHandler,true, serviceMethod, args, nil)
|
||||
if pCall.Err != nil {
|
||||
err = pCall.Err
|
||||
@@ -465,16 +463,16 @@ func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId str
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) callRpc(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, reply interface{}) error {
|
||||
var pClientList [maxClusterNode]*Client
|
||||
err, count := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
||||
pClientList :=make([]*Client,0,maxClusterNode)
|
||||
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList)
|
||||
if err != nil {
|
||||
log.Error("Call serviceMethod is failed",log.ErrorAttr("error",err))
|
||||
return err
|
||||
} else if count <= 0 {
|
||||
} else if len(pClientList) <= 0 {
|
||||
err = errors.New("Call serviceMethod is error:cannot find " + serviceMethod)
|
||||
log.Error("cannot find serviceMethod",log.String("serviceMethod",serviceMethod))
|
||||
return err
|
||||
} else if count > 1 {
|
||||
} else if len(pClientList) > 1 {
|
||||
log.Error("Cannot call more then 1 node!",log.String("serviceMethod",serviceMethod))
|
||||
return errors.New("cannot call more then 1 node")
|
||||
}
|
||||
@@ -509,9 +507,9 @@ func (handler *RpcHandler) asyncCallRpc(timeout time.Duration,nodeId string, ser
|
||||
}
|
||||
|
||||
reply := reflect.New(fVal.Type().In(0).Elem()).Interface()
|
||||
var pClientList [2]*Client
|
||||
err, count := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
||||
if count == 0 || err != nil {
|
||||
pClientList :=make([]*Client,0,1)
|
||||
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
||||
if len(pClientList) == 0 || err != nil {
|
||||
if err == nil {
|
||||
if nodeId != NodeIdNull {
|
||||
err = fmt.Errorf("cannot find %s from nodeId %d",serviceMethod,nodeId)
|
||||
@@ -524,7 +522,7 @@ func (handler *RpcHandler) asyncCallRpc(timeout time.Duration,nodeId string, ser
|
||||
return emptyCancelRpc,nil
|
||||
}
|
||||
|
||||
if count > 1 {
|
||||
if len(pClientList) > 1 {
|
||||
err := errors.New("cannot call more then 1 node")
|
||||
fVal.Call([]reflect.Value{reflect.ValueOf(reply), reflect.ValueOf(err)})
|
||||
log.Error("cannot call more then 1 node",log.String("serviceMethod",serviceMethod))
|
||||
@@ -540,10 +538,6 @@ func (handler *RpcHandler) GetName() string {
|
||||
return handler.rpcHandler.GetName()
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) IsSingleCoroutine() bool {
|
||||
return handler.rpcHandler.IsSingleCoroutine()
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) CallWithTimeout(timeout time.Duration,serviceMethod string, args interface{}, reply interface{}) error {
|
||||
return handler.callRpc(timeout,NodeIdNull, serviceMethod, args, reply)
|
||||
}
|
||||
@@ -593,12 +587,13 @@ func (handler *RpcHandler) CastGo(serviceMethod string, args interface{}) error
|
||||
|
||||
func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType, nodeId string, rpcMethodId uint32, serviceName string, rawArgs []byte) error {
|
||||
processor := GetProcessor(uint8(rpcProcessorType))
|
||||
err, count := handler.funcRpcClient(nodeId, serviceName,false, handler.pClientList)
|
||||
if count == 0 || err != nil {
|
||||
pClientList := make([]*Client,0,1)
|
||||
err, pClientList := handler.funcRpcClient(nodeId, serviceName,false, pClientList)
|
||||
if len(pClientList) == 0 || err != nil {
|
||||
log.Error("call serviceMethod is failed",log.ErrorAttr("error",err))
|
||||
return err
|
||||
}
|
||||
if count > 1 {
|
||||
if len(pClientList) > 1 {
|
||||
err := errors.New("cannot call more then 1 node")
|
||||
log.Error("cannot call more then 1 node",log.String("serviceName",serviceName))
|
||||
return err
|
||||
@@ -606,14 +601,14 @@ func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType, nodeId s
|
||||
|
||||
//2.rpcClient调用
|
||||
//如果调用本结点服务
|
||||
for i := 0; i < count; i++ {
|
||||
for i := 0; i < len(pClientList); i++ {
|
||||
//跨node调用
|
||||
pCall := handler.pClientList[i].RawGo(handler.pClientList[i].GetTargetNodeId(),DefaultRpcTimeout,handler.rpcHandler,processor, true, rpcMethodId, serviceName, rawArgs, nil)
|
||||
pCall := pClientList[i].RawGo(pClientList[i].GetTargetNodeId(),DefaultRpcTimeout,handler.rpcHandler,processor, true, rpcMethodId, serviceName, rawArgs, nil)
|
||||
if pCall.Err != nil {
|
||||
err = pCall.Err
|
||||
}
|
||||
|
||||
handler.pClientList[i].RemovePending(pCall.Seq)
|
||||
pClientList[i].RemovePending(pCall.Seq)
|
||||
ReleaseCall(pCall)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,14 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"github.com/duanhf2012/origin/v2/concurrent"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
var timerDispatcherLen = 100000
|
||||
var maxServiceEventChannelNum = 2000000
|
||||
|
||||
|
||||
|
||||
type IService interface {
|
||||
concurrent.IConcurrent
|
||||
Init(iService IService,getClientFun rpc.FuncRpcClient,getServerFun rpc.FuncRpcServer,serviceCfg interface{})
|
||||
@@ -55,6 +58,7 @@ type Service struct {
|
||||
serviceCfg interface{}
|
||||
goroutineNum int32
|
||||
startStatus bool
|
||||
isRelease int32
|
||||
retire int32
|
||||
eventProcessor event.IEventProcessor
|
||||
profiler *profiler.Profiler //性能分析器
|
||||
@@ -145,34 +149,36 @@ func (s *Service) Init(iService IService,getClientFun rpc.FuncRpcClient,getServe
|
||||
|
||||
func (s *Service) Start() {
|
||||
s.startStatus = true
|
||||
atomic.StoreInt32(&s.isRelease,0)
|
||||
var waitRun sync.WaitGroup
|
||||
log.Info(s.GetName()+" service is running",)
|
||||
s.self.(IService).OnStart()
|
||||
|
||||
for i:=int32(0);i< s.goroutineNum;i++{
|
||||
s.wg.Add(1)
|
||||
waitRun.Add(1)
|
||||
go func(){
|
||||
log.Info(s.GetName()+" service is running",)
|
||||
waitRun.Done()
|
||||
s.Run()
|
||||
s.run()
|
||||
}()
|
||||
}
|
||||
|
||||
waitRun.Wait()
|
||||
}
|
||||
|
||||
func (s *Service) Run() {
|
||||
func (s *Service) run() {
|
||||
defer s.wg.Done()
|
||||
var bStop = false
|
||||
|
||||
concurrent := s.IConcurrent.(*concurrent.Concurrent)
|
||||
concurrentCBChannel := concurrent.GetCallBackChannel()
|
||||
|
||||
s.self.(IService).OnStart()
|
||||
for{
|
||||
var analyzer *profiler.Analyzer
|
||||
select {
|
||||
case <- s.closeSig:
|
||||
bStop = true
|
||||
s.Release()
|
||||
concurrent.Close()
|
||||
case cb:=<-concurrentCBChannel:
|
||||
concurrent.DoCallback(cb)
|
||||
@@ -245,10 +251,6 @@ func (s *Service) Run() {
|
||||
}
|
||||
|
||||
if bStop == true {
|
||||
if atomic.AddInt32(&s.goroutineNum,-1)<=0 {
|
||||
s.startStatus = false
|
||||
s.Release()
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -271,8 +273,11 @@ func (s *Service) Release(){
|
||||
log.Dump(string(buf[:l]),log.String("error",errString))
|
||||
}
|
||||
}()
|
||||
|
||||
s.self.OnRelease()
|
||||
|
||||
if atomic.AddInt32(&s.isRelease,-1) == -1{
|
||||
s.self.OnRelease()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *Service) OnRelease(){
|
||||
@@ -293,6 +298,24 @@ func (s *Service) GetServiceCfg()interface{}{
|
||||
return s.serviceCfg
|
||||
}
|
||||
|
||||
func (s *Service) ParseServiceCfg(cfg interface{}) error{
|
||||
if s.serviceCfg == nil {
|
||||
return errors.New("no service configuration found")
|
||||
}
|
||||
|
||||
rv := reflect.ValueOf(s.serviceCfg)
|
||||
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||
return errors.New("no service configuration found")
|
||||
}
|
||||
|
||||
bytes,err := json.Marshal(s.serviceCfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal(bytes,cfg)
|
||||
}
|
||||
|
||||
func (s *Service) GetProfiler() *profiler.Profiler{
|
||||
return s.profiler
|
||||
}
|
||||
@@ -305,10 +328,6 @@ func (s *Service) UnRegEventReceiverFunc(eventType event.EventType, receiver eve
|
||||
s.eventProcessor.UnRegEventReceiverFun(eventType, receiver)
|
||||
}
|
||||
|
||||
func (s *Service) IsSingleCoroutine() bool {
|
||||
return s.goroutineNum == 1
|
||||
}
|
||||
|
||||
func (s *Service) RegRawRpc(rpcMethodId uint32,rawRpcCB rpc.RawRpcCallBack){
|
||||
s.rpcHandler.RegRawRpc(rpcMethodId,rawRpcCB)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func Init() {
|
||||
for _,s := range setupServiceList {
|
||||
err := s.OnInit()
|
||||
if err != nil {
|
||||
log.SError("Failed to initialize "+s.GetName()+" service:"+err.Error())
|
||||
log.Error("Failed to initialize "+s.GetName()+" service",log.ErrorAttr("err",err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
203
sysmodule/frametimer/FrameGroup.go
Normal file
203
sysmodule/frametimer/FrameGroup.go
Normal file
@@ -0,0 +1,203 @@
|
||||
package frametimer
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"github.com/duanhf2012/origin/v2/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TimerCB func(context.Context, FrameTimerID)
|
||||
|
||||
type _timerHeap struct {
|
||||
timers []*timerData
|
||||
}
|
||||
|
||||
func (h *_timerHeap) Len() int {
|
||||
return len(h.timers)
|
||||
}
|
||||
|
||||
func (h *_timerHeap) Less(i, j int) bool {
|
||||
return h.timers[i].frameNum < h.timers[j].frameNum
|
||||
}
|
||||
|
||||
func (h *_timerHeap) Swap(i, j int) {
|
||||
h.timers[i], h.timers[j] = h.timers[j], h.timers[i]
|
||||
h.timers[i].idx = i
|
||||
h.timers[j].idx = j
|
||||
}
|
||||
|
||||
func (h *_timerHeap) Push(x interface{}) {
|
||||
td := x.(*timerData)
|
||||
h.timers = append(h.timers, td)
|
||||
td.idx = len(h.timers) - 1
|
||||
}
|
||||
|
||||
func (h *_timerHeap) Pop() (ret interface{}) {
|
||||
l := len(h.timers)
|
||||
h.timers, ret = h.timers[:l-1], h.timers[l-1]
|
||||
return
|
||||
}
|
||||
|
||||
type FrameGroup struct {
|
||||
groupID FrameGroupID
|
||||
timerHeap _timerHeap
|
||||
ft *FrameTimer
|
||||
|
||||
preTickGlobalFrameNum FrameNumber // 上次tick全局帧
|
||||
preGlobalFrameNum FrameNumber // 上次设置的全局帧,用于更新FrameTimer.mapFrameGroup关系
|
||||
frameNum FrameNumber // 当前帧
|
||||
|
||||
pause bool // 暂停状态
|
||||
multiple uint8 // 位数,默认1倍,只允许1-5倍数
|
||||
}
|
||||
|
||||
func (fg *FrameGroup) init() {
|
||||
fg.timerHeap.timers = make([]*timerData, 0, 512)
|
||||
fg.groupID = fg.ft.genGroupID()
|
||||
fg.multiple = 1
|
||||
heap.Init(&fg.timerHeap)
|
||||
}
|
||||
|
||||
func (fg *FrameGroup) convertGlobalFrameNum(frameNum FrameNumber) FrameNumber {
|
||||
return fg.ft.getGlobalFrameNumber() + (frameNum-fg.frameNum)/FrameNumber(fg.multiple)
|
||||
}
|
||||
|
||||
func (fg *FrameGroup) refreshMinFrame() {
|
||||
if fg.timerHeap.Len() == 0 || fg.pause {
|
||||
return
|
||||
}
|
||||
|
||||
globalFrameNum := fg.convertGlobalFrameNum(fg.timerHeap.timers[0].frameNum)
|
||||
fg.ft.refreshGroupMinFrame(fg.groupID, fg.preGlobalFrameNum, globalFrameNum)
|
||||
fg.preGlobalFrameNum = globalFrameNum
|
||||
}
|
||||
|
||||
func (fg *FrameGroup) tick(globalFrame FrameNumber) {
|
||||
fg.frameNum = fg.frameNum + (globalFrame-fg.preTickGlobalFrameNum)*FrameNumber(fg.multiple)
|
||||
fg.preTickGlobalFrameNum = globalFrame
|
||||
|
||||
fg.onceTick()
|
||||
|
||||
fg.refreshMinFrame()
|
||||
}
|
||||
|
||||
func (fg *FrameGroup) onceTick() {
|
||||
for fg.timerHeap.Len() > 0 {
|
||||
if fg.timerHeap.timers[0].frameNum > fg.frameNum {
|
||||
break
|
||||
}
|
||||
|
||||
t := heap.Pop(&fg.timerHeap).(*timerData)
|
||||
|
||||
ev := event.NewEvent()
|
||||
ev.Type = event.Sys_Event_FrameTick
|
||||
ev.Data = t
|
||||
fg.ft.NotifyEvent(ev)
|
||||
fg.ft.removeTimerData(t.timerID)
|
||||
|
||||
if t.tickerFrameNum != 0 {
|
||||
fg.addTicker(t.timerID, t.tickerFrameNum, t.ctx, t.cb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (fg *FrameGroup) addTimer(timerID FrameTimerID, frame FrameNumber, ctx context.Context, cb TimerCB) {
|
||||
nextFrame := fg.frameNum + frame
|
||||
|
||||
td := fg.ft.addTimerData(timerID, nextFrame, 0, ctx, cb)
|
||||
heap.Push(&fg.timerHeap, td)
|
||||
}
|
||||
|
||||
func (fg *FrameGroup) addTicker(timerID FrameTimerID, frame FrameNumber, ctx context.Context, cb TimerCB) {
|
||||
nextFrame := fg.frameNum + frame
|
||||
|
||||
td := fg.ft.addTimerData(timerID, nextFrame, frame, ctx, cb)
|
||||
heap.Push(&fg.timerHeap, td)
|
||||
}
|
||||
|
||||
// SetMultiple 设置倍数,允许倍数范围1-5
|
||||
func (fg *FrameGroup) SetMultiple(multiple uint8) error {
|
||||
if fg.multiple == multiple {
|
||||
return nil
|
||||
}
|
||||
|
||||
if multiple < 0 || multiple > maxMultiple {
|
||||
return errors.New("invalid multiplier")
|
||||
}
|
||||
|
||||
fg.multiple = multiple
|
||||
|
||||
fg.refreshMinFrame()
|
||||
return nil
|
||||
}
|
||||
|
||||
// FrameAfterFunc 创建After定时器
|
||||
func (fg *FrameGroup) FrameAfterFunc(timerID *FrameTimerID, d time.Duration, ctx context.Context, cb TimerCB) {
|
||||
fg.ft.locker.Lock()
|
||||
defer fg.ft.locker.Unlock()
|
||||
|
||||
frame := FrameNumber(d / fg.ft.oneFrameTime)
|
||||
newTimerID := fg.ft.genTimerID()
|
||||
|
||||
fg.addTimer(newTimerID, frame, ctx, cb)
|
||||
*timerID = newTimerID
|
||||
fg.refreshMinFrame()
|
||||
}
|
||||
|
||||
// FrameNewTicker 创建Ticker定时器
|
||||
func (fg *FrameGroup) FrameNewTicker(timerID *FrameTimerID, d time.Duration, ctx context.Context, cb TimerCB) {
|
||||
fg.ft.locker.Lock()
|
||||
defer fg.ft.locker.Unlock()
|
||||
|
||||
frame := FrameNumber(d / fg.ft.oneFrameTime)
|
||||
newTimerID := fg.ft.genTimerID()
|
||||
|
||||
fg.addTicker(newTimerID, frame, ctx, cb)
|
||||
*timerID = newTimerID
|
||||
fg.refreshMinFrame()
|
||||
}
|
||||
|
||||
// Pause 暂停定时器组
|
||||
func (fg *FrameGroup) Pause() {
|
||||
fg.ft.locker.Lock()
|
||||
defer fg.ft.locker.Unlock()
|
||||
|
||||
fg.pause = true
|
||||
fg.ft.removeGroup(fg.groupID, fg.preGlobalFrameNum)
|
||||
fg.preGlobalFrameNum = 0
|
||||
}
|
||||
|
||||
// Resume 唤醒定时器组
|
||||
func (fg *FrameGroup) Resume() {
|
||||
fg.ft.locker.Lock()
|
||||
defer fg.ft.locker.Unlock()
|
||||
|
||||
fg.pause = false
|
||||
fg.refreshMinFrame()
|
||||
fg.preTickGlobalFrameNum = fg.ft.globalFrameNum
|
||||
}
|
||||
|
||||
// CancelTimer 关闭定时器
|
||||
func (fg *FrameGroup) CancelTimer(timerID FrameTimerID) {
|
||||
fg.ft.locker.Lock()
|
||||
defer fg.ft.locker.Unlock()
|
||||
|
||||
td := fg.ft.getTimerData(timerID)
|
||||
if td == nil {
|
||||
log.Error("cannot find timer", log.Uint64("timerID", uint64(timerID)))
|
||||
return
|
||||
}
|
||||
|
||||
heap.Remove(&fg.timerHeap, td.idx)
|
||||
fg.ft.removeGroup(fg.groupID, fg.preGlobalFrameNum)
|
||||
fg.preGlobalFrameNum = 0
|
||||
fg.refreshMinFrame()
|
||||
}
|
||||
|
||||
func (fg *FrameGroup) Close(){
|
||||
fg.ft.removeGroup(fg.groupID, fg.preGlobalFrameNum)
|
||||
delete(fg.ft.mapGroup,fg.groupID)
|
||||
}
|
||||
199
sysmodule/frametimer/FrameTimerModule.go
Normal file
199
sysmodule/frametimer/FrameTimerModule.go
Normal file
@@ -0,0 +1,199 @@
|
||||
package frametimer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"github.com/duanhf2012/origin/v2/log"
|
||||
"github.com/duanhf2012/origin/v2/service"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const defaultFps = 50
|
||||
const defaultSleepInterval = time.Millisecond * 3
|
||||
const maxFps = 1000
|
||||
const maxMultiple = 5
|
||||
|
||||
type FrameGroupID uint64
|
||||
type FrameTimerID uint64
|
||||
type FrameNumber uint64
|
||||
|
||||
type timerData struct {
|
||||
frameNum FrameNumber
|
||||
timerID FrameTimerID
|
||||
idx int
|
||||
cb TimerCB
|
||||
tickerFrameNum FrameNumber
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
type FrameTimer struct {
|
||||
service.Module
|
||||
fps uint32
|
||||
oneFrameTime time.Duration
|
||||
ticker *time.Ticker
|
||||
|
||||
mapFrameGroup map[FrameNumber]map[FrameGroupID]struct{}
|
||||
mapGroup map[FrameGroupID]*FrameGroup
|
||||
globalFrameNum FrameNumber // 当前帧
|
||||
|
||||
maxTimerID FrameTimerID
|
||||
maxGroupID FrameGroupID
|
||||
|
||||
mapTimer map[FrameTimerID]*timerData
|
||||
timerDataPool *sync.Pool
|
||||
|
||||
locker sync.Mutex
|
||||
sleepInterval time.Duration
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) getTimerData(timerID FrameTimerID) *timerData {
|
||||
return ft.mapTimer[timerID]
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) addTimerData(timerID FrameTimerID, frameNum FrameNumber, tickerFrameNum FrameNumber, ctx context.Context, cb TimerCB) *timerData {
|
||||
td := ft.timerDataPool.Get().(*timerData)
|
||||
td.timerID = timerID
|
||||
td.frameNum = frameNum
|
||||
td.cb = cb
|
||||
td.idx = -1
|
||||
td.tickerFrameNum = tickerFrameNum
|
||||
|
||||
ft.mapTimer[timerID] = td
|
||||
return td
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) removeTimerData(timerID FrameTimerID) {
|
||||
td := ft.mapTimer[timerID]
|
||||
if td == nil {
|
||||
return
|
||||
}
|
||||
|
||||
ft.timerDataPool.Put(td)
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) genGroupID() FrameGroupID {
|
||||
ft.maxGroupID++
|
||||
return ft.maxGroupID
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) genTimerID() FrameTimerID {
|
||||
ft.maxTimerID++
|
||||
return ft.maxTimerID
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) getGlobalFrameNumber() FrameNumber {
|
||||
return ft.globalFrameNum
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) frameTick() {
|
||||
preFrameNum := ft.globalFrameNum
|
||||
ft.globalFrameNum++
|
||||
|
||||
ft.locker.Lock()
|
||||
defer ft.locker.Unlock()
|
||||
for i := preFrameNum; i <= ft.globalFrameNum; i++ {
|
||||
mapGroup := ft.mapFrameGroup[i]
|
||||
delete(ft.mapFrameGroup, i)
|
||||
for groupID := range mapGroup {
|
||||
group := ft.mapGroup[groupID]
|
||||
if group == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
group.tick(ft.globalFrameNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) removeGroup(groupID FrameGroupID, frameNum FrameNumber) {
|
||||
delete(ft.mapFrameGroup[frameNum], groupID)
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) refreshGroupMinFrame(groupID FrameGroupID, preFrameNum FrameNumber, newFrameNum FrameNumber) {
|
||||
ft.removeGroup(groupID, preFrameNum)
|
||||
|
||||
mapGroup := ft.mapFrameGroup[newFrameNum]
|
||||
if mapGroup == nil {
|
||||
mapGroup = make(map[FrameGroupID]struct{}, 6)
|
||||
ft.mapFrameGroup[newFrameNum] = mapGroup
|
||||
}
|
||||
|
||||
mapGroup[groupID] = struct{}{}
|
||||
}
|
||||
|
||||
func (ft *FrameTimer) OnInit() error {
|
||||
ft.mapFrameGroup = make(map[FrameNumber]map[FrameGroupID]struct{}, 1024)
|
||||
ft.mapGroup = make(map[FrameGroupID]*FrameGroup, 1024)
|
||||
ft.mapTimer = make(map[FrameTimerID]*timerData, 2048)
|
||||
ft.timerDataPool = &sync.Pool{
|
||||
New: func() any {
|
||||
return &timerData{}
|
||||
},
|
||||
}
|
||||
|
||||
if ft.fps == 0 {
|
||||
ft.fps = defaultFps
|
||||
}
|
||||
|
||||
ft.GetEventProcessor().RegEventReceiverFunc(event.Sys_Event_FrameTick, ft.GetEventHandler(), func(e event.IEvent) {
|
||||
ev := e.(*event.Event)
|
||||
td, ok := ev.Data.(*timerData)
|
||||
if !ok {
|
||||
log.Error("convert *timerData error")
|
||||
return
|
||||
}
|
||||
td.cb(td.ctx, td.timerID)
|
||||
event.DeleteEvent(e)
|
||||
})
|
||||
|
||||
ft.oneFrameTime = time.Second / time.Duration(ft.fps)
|
||||
ft.ticker = time.NewTicker(ft.oneFrameTime)
|
||||
|
||||
if ft.sleepInterval == 0 {
|
||||
ft.sleepInterval = defaultSleepInterval
|
||||
}
|
||||
|
||||
go func() {
|
||||
preTime := time.Now()
|
||||
var preFrame FrameNumber
|
||||
|
||||
for {
|
||||
time.Sleep(ft.sleepInterval)
|
||||
frameMax := FrameNumber(time.Now().Sub(preTime) / ft.oneFrameTime)
|
||||
for i := preFrame + 1; i <= frameMax; i++ {
|
||||
ft.frameTick()
|
||||
}
|
||||
|
||||
preFrame = frameMax
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetFps 设置帧率,越大误差越低。如果有倍数加速需求,可以适当加大fps,以减少误差。默认50fps
|
||||
func (ft *FrameTimer) SetFps(fps uint32) {
|
||||
if fps > maxFps {
|
||||
fps = maxFps
|
||||
}
|
||||
|
||||
ft.fps = fps
|
||||
}
|
||||
|
||||
// SetAccuracyInterval 设置时间间隔精度,在循环中sleep该时间进行判断。实际上因为sleep有误差,所以暂时不使用fps得出。默认为3ms
|
||||
func (ft *FrameTimer) SetAccuracyInterval(interval time.Duration) {
|
||||
ft.sleepInterval = interval
|
||||
}
|
||||
|
||||
// NewGroup 创建定时器组
|
||||
func (ft *FrameTimer) NewGroup() *FrameGroup {
|
||||
var group FrameGroup
|
||||
group.ft = ft
|
||||
group.init()
|
||||
|
||||
ft.locker.Lock()
|
||||
defer ft.locker.Unlock()
|
||||
ft.mapGroup[group.groupID] = &group
|
||||
return &group
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package ginmodule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"datacenter/common/processor"
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"github.com/duanhf2012/origin/v2/log"
|
||||
"github.com/duanhf2012/origin/v2/service"
|
||||
@@ -10,34 +9,36 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
"io"
|
||||
)
|
||||
|
||||
type IGinProcessor interface {
|
||||
Process(data *gin.Context) (*gin.Context, error)
|
||||
}
|
||||
|
||||
type GinModule struct {
|
||||
service.Module
|
||||
|
||||
*GinConf
|
||||
*gin.Engine
|
||||
srv *http.Server
|
||||
|
||||
processor []processor.IGinProcessor
|
||||
listenAddr string
|
||||
handleTimeout time.Duration
|
||||
processor []IGinProcessor
|
||||
}
|
||||
|
||||
type GinConf struct {
|
||||
Addr string
|
||||
}
|
||||
|
||||
const Sys_Event_Gin_Event event.EventType = -11
|
||||
|
||||
func (gm *GinModule) Init(conf *GinConf, engine *gin.Engine) {
|
||||
gm.GinConf = conf
|
||||
func (gm *GinModule) Init(addr string, handleTimeout time.Duration,engine *gin.Engine) {
|
||||
gm.listenAddr = addr
|
||||
gm.handleTimeout = handleTimeout
|
||||
gm.Engine = engine
|
||||
}
|
||||
|
||||
func (gm *GinModule) SetupDataProcessor(processor ...processor.IGinProcessor) {
|
||||
func (gm *GinModule) SetupDataProcessor(processor ...IGinProcessor) {
|
||||
gm.processor = processor
|
||||
}
|
||||
|
||||
func (gm *GinModule) AppendDataProcessor(processor ...processor.IGinProcessor) {
|
||||
func (gm *GinModule) AppendDataProcessor(processor ...IGinProcessor) {
|
||||
gm.processor = append(gm.processor, processor...)
|
||||
}
|
||||
|
||||
@@ -47,27 +48,28 @@ func (gm *GinModule) OnInit() error {
|
||||
}
|
||||
|
||||
gm.srv = &http.Server{
|
||||
Addr: gm.Addr,
|
||||
Addr: gm.listenAddr,
|
||||
Handler: gm.Engine,
|
||||
}
|
||||
|
||||
gm.Engine.Use(Logger())
|
||||
gm.Engine.Use(gin.Recovery())
|
||||
gm.GetEventProcessor().RegEventReceiverFunc(Sys_Event_Gin_Event, gm.GetEventHandler(), gm.eventHandler)
|
||||
gm.GetEventProcessor().RegEventReceiverFunc(event.Sys_Event_Gin_Event, gm.GetEventHandler(), gm.eventHandler)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gm *GinModule) eventHandler(ev event.IEvent) {
|
||||
ginEvent := ev.(*GinEvent)
|
||||
for _, handler := range ginEvent.handlersChain {
|
||||
handler(ginEvent.c)
|
||||
handler(&ginEvent.c)
|
||||
}
|
||||
|
||||
ginEvent.chanWait <- struct{}{}
|
||||
//ginEvent.chanWait <- struct{}{}
|
||||
}
|
||||
|
||||
func (gm *GinModule) Start() {
|
||||
log.Info("http start listen", slog.Any("addr", gm.Addr))
|
||||
gm.srv.Addr = gm.listenAddr
|
||||
log.Info("http start listen", slog.Any("addr", gm.listenAddr))
|
||||
go func() {
|
||||
err := gm.srv.ListenAndServe()
|
||||
if err != nil {
|
||||
@@ -77,7 +79,7 @@ func (gm *GinModule) Start() {
|
||||
}
|
||||
|
||||
func (gm *GinModule) StartTLS(certFile, keyFile string) {
|
||||
log.Info("http start listen", slog.Any("addr", gm.Addr))
|
||||
log.Info("http start listen", slog.Any("addr", gm.listenAddr))
|
||||
go func() {
|
||||
err := gm.srv.ListenAndServeTLS(certFile, keyFile)
|
||||
if err != nil {
|
||||
@@ -88,21 +90,106 @@ func (gm *GinModule) StartTLS(certFile, keyFile string) {
|
||||
|
||||
func (gm *GinModule) Stop(ctx context.Context) {
|
||||
if err := gm.srv.Shutdown(ctx); err != nil {
|
||||
log.SError("Server Shutdown", slog.Any("error", err))
|
||||
log.Error("Server Shutdown", slog.Any("error", err))
|
||||
}
|
||||
}
|
||||
|
||||
type GinEvent struct {
|
||||
handlersChain gin.HandlersChain
|
||||
type SafeContext struct {
|
||||
*gin.Context
|
||||
chanWait chan struct{}
|
||||
c *gin.Context
|
||||
}
|
||||
|
||||
func (c *SafeContext) JSONAndDone(code int, obj any) {
|
||||
c.Context.JSON(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) AsciiJSONAndDone(code int, obj any){
|
||||
c.Context.AsciiJSON(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) PureJSONAndDone(code int, obj any){
|
||||
c.Context.PureJSON(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) XMLAndDone(code int, obj any){
|
||||
c.Context.XML(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) YAMLAndDone(code int, obj any){
|
||||
c.Context.YAML(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) TOMLAndDone(code int, obj any){
|
||||
c.Context.TOML(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) ProtoBufAndDone(code int, obj any){
|
||||
c.Context.ProtoBuf(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) StringAndDone(code int, format string, values ...any){
|
||||
c.Context.String(code,format,values...)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) RedirectAndDone(code int, location string){
|
||||
c.Context.Redirect(code,location)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) DataAndDone(code int, contentType string, data []byte){
|
||||
c.Context.Data(code,contentType,data)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) DataFromReaderAndDone(code int, contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string){
|
||||
c.DataFromReader(code,contentLength,contentType,reader,extraHeaders)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) HTMLAndDone(code int, name string, obj any){
|
||||
c.Context.HTML(code,name,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) IndentedJSONAndDone(code int, obj any){
|
||||
c.Context.IndentedJSON(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) SecureJSONAndDone(code int, obj any){
|
||||
c.Context.SecureJSON(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) JSONPAndDone(code int, obj any){
|
||||
c.Context.JSONP(code,obj)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func (c *SafeContext) Done(){
|
||||
c.chanWait <- struct{}{}
|
||||
}
|
||||
|
||||
type GinEvent struct {
|
||||
handlersChain []SafeHandlerFunc
|
||||
c SafeContext
|
||||
}
|
||||
|
||||
type SafeHandlerFunc func(*SafeContext)
|
||||
|
||||
func (ge *GinEvent) GetEventType() event.EventType {
|
||||
return Sys_Event_Gin_Event
|
||||
return event.Sys_Event_Gin_Event
|
||||
}
|
||||
|
||||
func (gm *GinModule) handleMethod(httpMethod, relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
func (gm *GinModule) handleMethod(httpMethod, relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||
return gm.Engine.Handle(httpMethod, relativePath, func(c *gin.Context) {
|
||||
for _, p := range gm.processor {
|
||||
_, err := p.Process(c)
|
||||
@@ -112,33 +199,71 @@ func (gm *GinModule) handleMethod(httpMethod, relativePath string, handlers ...g
|
||||
}
|
||||
|
||||
var ev GinEvent
|
||||
chanWait := make(chan struct{})
|
||||
ev.chanWait = chanWait
|
||||
chanWait := make(chan struct{},2)
|
||||
ev.c.chanWait = chanWait
|
||||
ev.handlersChain = handlers
|
||||
ev.c = c
|
||||
ev.c.Context = c
|
||||
gm.NotifyEvent(&ev)
|
||||
|
||||
<-chanWait
|
||||
ctx,cancel := context.WithTimeout(context.Background(), gm.handleTimeout)
|
||||
defer cancel()
|
||||
|
||||
select{
|
||||
case <-ctx.Done():
|
||||
log.Error("GinModule process timeout", slog.Any("path", c.Request.URL.Path))
|
||||
c.AbortWithStatus(http.StatusRequestTimeout)
|
||||
case <-chanWait:
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (gm *GinModule) SafeGET(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
// GET 回调处理是在gin协程中
|
||||
func (gm *GinModule) GET(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
return gm.Engine.GET(relativePath, handlers...)
|
||||
}
|
||||
|
||||
// POST 回调处理是在gin协程中
|
||||
func (gm *GinModule) POST(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
return gm.Engine.POST(relativePath, handlers...)
|
||||
}
|
||||
|
||||
// DELETE 回调处理是在gin协程中
|
||||
func (gm *GinModule) DELETE(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
return gm.Engine.DELETE(relativePath, handlers...)
|
||||
}
|
||||
|
||||
// PATCH 回调处理是在gin协程中
|
||||
func (gm *GinModule) PATCH(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
return gm.Engine.PATCH(relativePath, handlers...)
|
||||
}
|
||||
|
||||
// Put 回调处理是在gin协程中
|
||||
func (gm *GinModule) Put(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
return gm.Engine.PUT(relativePath, handlers...)
|
||||
}
|
||||
|
||||
// SafeGET 回调处理是在service协程中
|
||||
func (gm *GinModule) SafeGET(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||
return gm.handleMethod(http.MethodGet, relativePath, handlers...)
|
||||
}
|
||||
|
||||
func (gm *GinModule) SafePOST(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
// SafePOST 回调处理是在service协程中
|
||||
func (gm *GinModule) SafePOST(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||
return gm.handleMethod(http.MethodPost, relativePath, handlers...)
|
||||
}
|
||||
|
||||
func (gm *GinModule) SafeDELETE(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
// SafeDELETE 回调处理是在service协程中
|
||||
func (gm *GinModule) SafeDELETE(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||
return gm.handleMethod(http.MethodDelete, relativePath, handlers...)
|
||||
}
|
||||
|
||||
func (gm *GinModule) SafePATCH(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
// SafePATCH 回调处理是在service协程中
|
||||
func (gm *GinModule) SafePATCH(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||
return gm.handleMethod(http.MethodPatch, relativePath, handlers...)
|
||||
}
|
||||
|
||||
func (gm *GinModule) SafePut(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
// SafePut 回调处理是在service协程中
|
||||
func (gm *GinModule) SafePut(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||
return gm.handleMethod(http.MethodPut, relativePath, handlers...)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package ginmodule
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duanhf2012/origin/log"
|
||||
"github.com/duanhf2012/origin/v2/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
)
|
||||
@@ -44,7 +44,7 @@ func Logger() gin.HandlerFunc {
|
||||
// 响应状态码
|
||||
statusCode := c.Writer.Status()
|
||||
|
||||
log.SDebug(fmt.Sprintf(
|
||||
log.Debug(fmt.Sprintf(
|
||||
"%s | %3d | %s %10s | \033[44;37m%-6s\033[0m %s %s | %10v | \"%s\" \"%s\"",
|
||||
colorForStatus(statusCode),
|
||||
statusCode,
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -48,6 +47,10 @@ func (mm *MongoModule) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *MongoModule) Stop() error {
|
||||
return mm.client.Disconnect(context.Background())
|
||||
}
|
||||
|
||||
func (mm *MongoModule) TakeSession() Session {
|
||||
return Session{Client: mm.client, maxOperatorTimeOut: mm.maxOperatorTimeOut}
|
||||
}
|
||||
@@ -86,12 +89,12 @@ func (s *Session) EnsureUniqueIndex(db string, collection string, indexKeys [][]
|
||||
func (s *Session) ensureIndex(db string, collection string, indexKeys [][]string, bBackground bool, unique bool, sparse bool, asc bool) error {
|
||||
var indexes []mongo.IndexModel
|
||||
for _, keys := range indexKeys {
|
||||
keysDoc := bsonx.Doc{}
|
||||
keysDoc := bson.D{}
|
||||
for _, key := range keys {
|
||||
if asc {
|
||||
keysDoc = keysDoc.Append(key, bsonx.Int32(1))
|
||||
keysDoc = append(keysDoc, bson.E{Key:key,Value:1})
|
||||
} else {
|
||||
keysDoc = keysDoc.Append(key, bsonx.Int32(-1))
|
||||
keysDoc = append(keysDoc, bson.E{Key:key,Value:-1})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type CustomerSubscriber struct {
|
||||
rpc.IRpcHandler
|
||||
topic string
|
||||
subscriber *Subscriber
|
||||
fromNodeId int
|
||||
fromNodeId string
|
||||
callBackRpcMethod string
|
||||
serviceName string
|
||||
StartIndex uint64
|
||||
@@ -37,7 +37,7 @@ const (
|
||||
MethodLast SubscribeMethod = 1 //Last模式,以该消费者上次记录的位置开始订阅
|
||||
)
|
||||
|
||||
func (cs *CustomerSubscriber) trySetSubscriberBaseInfo(rpcHandler rpc.IRpcHandler, ss *Subscriber, topic string, subscribeMethod SubscribeMethod, customerId string, fromNodeId int, callBackRpcMethod string, startIndex uint64, oneBatchQuantity int32) error {
|
||||
func (cs *CustomerSubscriber) trySetSubscriberBaseInfo(rpcHandler rpc.IRpcHandler, ss *Subscriber, topic string, subscribeMethod SubscribeMethod, customerId string, fromNodeId string, callBackRpcMethod string, startIndex uint64, oneBatchQuantity int32) error {
|
||||
cs.subscriber = ss
|
||||
cs.fromNodeId = fromNodeId
|
||||
cs.callBackRpcMethod = callBackRpcMethod
|
||||
@@ -85,7 +85,7 @@ func (cs *CustomerSubscriber) trySetSubscriberBaseInfo(rpcHandler rpc.IRpcHandle
|
||||
}
|
||||
|
||||
// 开始订阅
|
||||
func (cs *CustomerSubscriber) Subscribe(rpcHandler rpc.IRpcHandler, ss *Subscriber, topic string, subscribeMethod SubscribeMethod, customerId string, fromNodeId int, callBackRpcMethod string, startIndex uint64, oneBatchQuantity int32) error {
|
||||
func (cs *CustomerSubscriber) Subscribe(rpcHandler rpc.IRpcHandler, ss *Subscriber, topic string, subscribeMethod SubscribeMethod, customerId string, fromNodeId string, callBackRpcMethod string, startIndex uint64, oneBatchQuantity int32) error {
|
||||
err := cs.trySetSubscriberBaseInfo(rpcHandler, ss, topic, subscribeMethod, customerId, fromNodeId, callBackRpcMethod, startIndex, oneBatchQuantity)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -122,5 +122,5 @@ func (ms *MessageQueueService) RPC_Publish(inParam *rpc.DBQueuePublishReq, outPa
|
||||
|
||||
func (ms *MessageQueueService) RPC_Subscribe(req *rpc.DBQueueSubscribeReq, res *rpc.DBQueueSubscribeRes) error {
|
||||
topicRoom := ms.GetTopicRoom(req.TopicName)
|
||||
return topicRoom.TopicSubscribe(ms.GetRpcHandler(), req.SubType, int32(req.Method), int(req.FromNodeId), req.RpcMethod, req.TopicName, req.CustomerId, req.StartIndex, req.OneBatchQuantity)
|
||||
return topicRoom.TopicSubscribe(ms.GetRpcHandler(), req.SubType, int32(req.Method), req.FromNodeId, req.RpcMethod, req.TopicName, req.CustomerId, req.StartIndex, req.OneBatchQuantity)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func (ss *Subscriber) PersistTopicData(topic string, topics []TopicData, retryCo
|
||||
return ss.dataPersist.PersistTopicData(topic, topics, retryCount)
|
||||
}
|
||||
|
||||
func (ss *Subscriber) TopicSubscribe(rpcHandler rpc.IRpcHandler, subScribeType rpc.SubscribeType, subscribeMethod SubscribeMethod, fromNodeId int, callBackRpcMethod string, topic string, customerId string, StartIndex uint64, oneBatchQuantity int32) error {
|
||||
func (ss *Subscriber) TopicSubscribe(rpcHandler rpc.IRpcHandler, subScribeType rpc.SubscribeType, subscribeMethod SubscribeMethod, fromNodeId string, callBackRpcMethod string, topic string, customerId string, StartIndex uint64, oneBatchQuantity int32) error {
|
||||
//取消订阅时
|
||||
if subScribeType == rpc.SubscribeType_Unsubscribe {
|
||||
ss.UnSubscribe(customerId)
|
||||
|
||||
@@ -263,7 +263,7 @@ func (mp *MongoPersist) JugeTimeoutSave() bool{
|
||||
|
||||
func (mp *MongoPersist) persistCoroutine(){
|
||||
defer mp.waitGroup.Done()
|
||||
for atomic.LoadInt32(&mp.stop)==0 || mp.hasPersistData(){
|
||||
for atomic.LoadInt32(&mp.stop)==0 {
|
||||
//间隔时间sleep
|
||||
time.Sleep(time.Second*1)
|
||||
|
||||
|
||||
@@ -107,12 +107,16 @@ func (tcpService *TcpService) TcpEventHandler(ev event.IEvent) {
|
||||
case TPT_DisConnected:
|
||||
tcpService.process.DisConnectedRoute(pack.ClientId)
|
||||
case TPT_UnknownPack:
|
||||
tcpService.process.UnknownMsgRoute(pack.ClientId,pack.Data)
|
||||
tcpService.process.UnknownMsgRoute(pack.ClientId,pack.Data,tcpService.recyclerReaderBytes)
|
||||
case TPT_Pack:
|
||||
tcpService.process.MsgRoute(pack.ClientId,pack.Data)
|
||||
tcpService.process.MsgRoute(pack.ClientId,pack.Data,tcpService.recyclerReaderBytes)
|
||||
}
|
||||
}
|
||||
|
||||
func (tcpService *TcpService) recyclerReaderBytes(data []byte) {
|
||||
}
|
||||
|
||||
|
||||
func (tcpService *TcpService) SetProcessor(process processor.IProcessor,handler event.IEventHandler){
|
||||
tcpService.process = process
|
||||
tcpService.RegEventReceiverFunc(event.Sys_Event_Tcp,handler, tcpService.TcpEventHandler)
|
||||
|
||||
@@ -95,9 +95,9 @@ func (ws *WSService) WSEventHandler(ev event.IEvent) {
|
||||
case WPT_DisConnected:
|
||||
pack.MsgProcessor.DisConnectedRoute(pack.ClientId)
|
||||
case WPT_UnknownPack:
|
||||
pack.MsgProcessor.UnknownMsgRoute(pack.ClientId,pack.Data)
|
||||
pack.MsgProcessor.UnknownMsgRoute(pack.ClientId,pack.Data,ws.recyclerReaderBytes)
|
||||
case WPT_Pack:
|
||||
pack.MsgProcessor.MsgRoute(pack.ClientId,pack.Data)
|
||||
pack.MsgProcessor.MsgRoute(pack.ClientId,pack.Data,ws.recyclerReaderBytes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func (slf *WSClient) Run() {
|
||||
for{
|
||||
bytes,err := slf.wsConn.ReadMsg()
|
||||
if err != nil {
|
||||
log.Debug("read client id %d is error:%+v",slf.id,err)
|
||||
log.Debug("read client id %s is error:%+v",slf.id,err)
|
||||
break
|
||||
}
|
||||
data,err:=slf.wsService.process.Unmarshal(slf.id,bytes)
|
||||
@@ -153,7 +153,7 @@ func (ws *WSService) SendMsg(clientid string,msg interface{}) error{
|
||||
client,ok := ws.mapClient[clientid]
|
||||
if ok == false{
|
||||
ws.mapClientLocker.Unlock()
|
||||
return fmt.Errorf("client %d is disconnect!",clientid)
|
||||
return fmt.Errorf("client %s is disconnect!",clientid)
|
||||
}
|
||||
|
||||
ws.mapClientLocker.Unlock()
|
||||
@@ -180,3 +180,5 @@ func (ws *WSService) Close(clientid string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ws *WSService) recyclerReaderBytes(data []byte) {
|
||||
}
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
package math
|
||||
|
||||
import (
|
||||
"github.com/duanhf2012/origin/v2/log"
|
||||
)
|
||||
|
||||
type NumberType interface {
|
||||
int | int8 | int16 | int32 | int64 | float32 | float64 | uint | uint8 | uint16 | uint32 | uint64
|
||||
}
|
||||
|
||||
type SignedNumberType interface {
|
||||
int | int8 | int16 | int32 | int64 | float32 | float64
|
||||
}
|
||||
|
||||
type FloatType interface {
|
||||
float32 | float64
|
||||
}
|
||||
|
||||
func Max[NumType NumberType](number1 NumType, number2 NumType) NumType {
|
||||
if number1 > number2 {
|
||||
return number1
|
||||
}
|
||||
|
||||
return number2
|
||||
}
|
||||
|
||||
func Min[NumType NumberType](number1 NumType, number2 NumType) NumType {
|
||||
if number1 < number2 {
|
||||
return number1
|
||||
}
|
||||
|
||||
return number2
|
||||
}
|
||||
|
||||
func Abs[NumType SignedNumberType](Num NumType) NumType {
|
||||
if Num < 0 {
|
||||
return -1 * Num
|
||||
}
|
||||
|
||||
return Num
|
||||
}
|
||||
|
||||
func AddSafe[NumType NumberType](number1 NumType, number2 NumType) (NumType, bool) {
|
||||
ret := number1 + number2
|
||||
if number2 > 0 && ret < number1 {
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, false
|
||||
} else if number2 < 0 && ret > number1 {
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, false
|
||||
}
|
||||
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func SubSafe[NumType NumberType](number1 NumType, number2 NumType) (NumType, bool) {
|
||||
ret := number1 - number2
|
||||
if number2 > 0 && ret > number1 {
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, false
|
||||
} else if number2 < 0 && ret < number1 {
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, false
|
||||
}
|
||||
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func MulSafe[NumType NumberType](number1 NumType, number2 NumType) (NumType, bool) {
|
||||
ret := number1 * number2
|
||||
if number1 == 0 || number2 == 0 {
|
||||
return ret, true
|
||||
}
|
||||
|
||||
if ret/number2 == number1 {
|
||||
return ret, true
|
||||
}
|
||||
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func Add[NumType NumberType](number1 NumType, number2 NumType) NumType {
|
||||
ret, _ := AddSafe(number1, number2)
|
||||
return ret
|
||||
}
|
||||
|
||||
func Sub[NumType NumberType](number1 NumType, number2 NumType) NumType {
|
||||
ret, _ := SubSafe(number1, number2)
|
||||
return ret
|
||||
}
|
||||
|
||||
func Mul[NumType NumberType](number1 NumType, number2 NumType) NumType {
|
||||
ret, _ := MulSafe(number1, number2)
|
||||
return ret
|
||||
}
|
||||
|
||||
// 安全的求比例
|
||||
func PercentRateSafe[NumType NumberType, OutNumType NumberType](maxValue int64, rate NumType, numbers ...NumType) (OutNumType, bool) {
|
||||
// 比例不能为负数
|
||||
if rate < 0 {
|
||||
log.Stack("rate must not positive")
|
||||
return 0, false
|
||||
}
|
||||
|
||||
if rate == 0 {
|
||||
// 比例为0
|
||||
return 0, true
|
||||
}
|
||||
|
||||
ret := int64(rate)
|
||||
for _, number := range numbers {
|
||||
number64 := int64(number)
|
||||
result, success := MulSafe(number64, ret)
|
||||
if !success {
|
||||
// 基数*比例越界了,int64都越界了,没办法了
|
||||
return 0, false
|
||||
}
|
||||
|
||||
ret = result
|
||||
}
|
||||
|
||||
ret = ret / 10000
|
||||
if ret > maxValue {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return OutNumType(ret), true
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package rand
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func RandGroup(p ...uint32) int {
|
||||
if p == nil {
|
||||
panic("args not found")
|
||||
}
|
||||
|
||||
r := make([]uint32, len(p))
|
||||
for i := 0; i < len(p); i++ {
|
||||
if i == 0 {
|
||||
r[0] = p[0]
|
||||
} else {
|
||||
r[i] = r[i-1] + p[i]
|
||||
}
|
||||
}
|
||||
|
||||
rl := r[len(r)-1]
|
||||
if rl == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
rn := uint32(rand.Int63n(int64(rl)))
|
||||
for i := 0; i < len(r); i++ {
|
||||
if rn < r[i] {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
panic("bug")
|
||||
}
|
||||
|
||||
func RandInterval(b1, b2 int32) int32 {
|
||||
if b1 == b2 {
|
||||
return b1
|
||||
}
|
||||
|
||||
min, max := int64(b1), int64(b2)
|
||||
if min > max {
|
||||
min, max = max, min
|
||||
}
|
||||
return int32(rand.Int63n(max-min+1) + min)
|
||||
}
|
||||
|
||||
func RandIntervalN(b1, b2 int32, n uint32) []int32 {
|
||||
if b1 == b2 {
|
||||
return []int32{b1}
|
||||
}
|
||||
|
||||
min, max := int64(b1), int64(b2)
|
||||
if min > max {
|
||||
min, max = max, min
|
||||
}
|
||||
l := max - min + 1
|
||||
if int64(n) > l {
|
||||
n = uint32(l)
|
||||
}
|
||||
|
||||
r := make([]int32, n)
|
||||
m := make(map[int32]int32)
|
||||
for i := uint32(0); i < n; i++ {
|
||||
v := int32(rand.Int63n(l) + min)
|
||||
|
||||
if mv, ok := m[v]; ok {
|
||||
r[i] = mv
|
||||
} else {
|
||||
r[i] = v
|
||||
}
|
||||
|
||||
lv := int32(l - 1 + min)
|
||||
if v != lv {
|
||||
if mv, ok := m[lv]; ok {
|
||||
m[v] = mv
|
||||
} else {
|
||||
m[v] = lv
|
||||
}
|
||||
}
|
||||
|
||||
l--
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
86
util/smath/smath.go
Normal file
86
util/smath/smath.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package smath
|
||||
|
||||
import (
|
||||
"github.com/duanhf2012/origin/v2/log"
|
||||
"github.com/duanhf2012/origin/v2/util/typedef"
|
||||
)
|
||||
|
||||
func Max[NumType typedef.Number](number1 NumType, number2 NumType) NumType {
|
||||
if number1 > number2 {
|
||||
return number1
|
||||
}
|
||||
|
||||
return number2
|
||||
}
|
||||
|
||||
func Min[NumType typedef.Number](number1 NumType, number2 NumType) NumType {
|
||||
if number1 < number2 {
|
||||
return number1
|
||||
}
|
||||
|
||||
return number2
|
||||
}
|
||||
|
||||
func Abs[NumType typedef.Signed|typedef.Float](Num NumType) NumType {
|
||||
if Num < 0 {
|
||||
return -1 * Num
|
||||
}
|
||||
|
||||
return Num
|
||||
}
|
||||
|
||||
func AddSafe[NumType typedef.Number](number1 NumType, number2 NumType) (NumType, bool) {
|
||||
ret := number1 + number2
|
||||
if number2 > 0 && ret < number1 {
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, false
|
||||
} else if number2 < 0 && ret > number1 {
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, false
|
||||
}
|
||||
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func SubSafe[NumType typedef.Number](number1 NumType, number2 NumType) (NumType, bool) {
|
||||
ret := number1 - number2
|
||||
if number2 > 0 && ret > number1 {
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, false
|
||||
} else if number2 < 0 && ret < number1 {
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, false
|
||||
}
|
||||
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func MulSafe[NumType typedef.Number](number1 NumType, number2 NumType) (NumType, bool) {
|
||||
ret := number1 * number2
|
||||
if number1 == 0 || number2 == 0 {
|
||||
return ret, true
|
||||
}
|
||||
|
||||
if ret/number2 == number1 {
|
||||
return ret, true
|
||||
}
|
||||
|
||||
log.Stack("Calculation overflow", log.Any("number1", number1), log.Any("number2", number2))
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func Add[NumType typedef.Number](number1 NumType, number2 NumType) NumType {
|
||||
ret, _ := AddSafe(number1, number2)
|
||||
return ret
|
||||
}
|
||||
|
||||
func Sub[NumType typedef.Number](number1 NumType, number2 NumType) NumType {
|
||||
ret, _ := SubSafe(number1, number2)
|
||||
return ret
|
||||
}
|
||||
|
||||
func Mul[NumType typedef.Number](number1 NumType, number2 NumType) NumType {
|
||||
ret, _ := MulSafe(number1, number2)
|
||||
return ret
|
||||
}
|
||||
|
||||
107
util/srand/slice.go
Normal file
107
util/srand/slice.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package srand
|
||||
|
||||
import (
|
||||
"github.com/duanhf2012/origin/v2/util/typedef"
|
||||
"math/rand"
|
||||
"slices"
|
||||
)
|
||||
|
||||
func Sum[E ~[]T, T typedef.Number](arr E) T {
|
||||
var sum T
|
||||
for i := range arr {
|
||||
sum += arr[i]
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func SumFunc[E ~[]V, V any, T typedef.Number](arr E, getValue func(i int) T) T {
|
||||
var sum T
|
||||
for i := range arr {
|
||||
sum += getValue(i)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func Shuffle[E ~[]T, T any](arr E) {
|
||||
rand.Shuffle(len(arr), func(i, j int) {
|
||||
arr[i], arr[j] = arr[j], arr[i]
|
||||
})
|
||||
}
|
||||
|
||||
func RandOne[E ~[]T, T any](arr E) T {
|
||||
return arr[rand.Intn(len(arr))]
|
||||
}
|
||||
|
||||
func RandN[E ~[]T, T any](arr E, num int) []T {
|
||||
index := make([]int, 0, len(arr))
|
||||
for i := range arr {
|
||||
index = append(index, i)
|
||||
}
|
||||
Shuffle(index)
|
||||
if len(index) > num {
|
||||
index = index
|
||||
}
|
||||
ret := make([]T, 0, len(index))
|
||||
for i := range index {
|
||||
ret = append(ret, arr[index[i]])
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func RandWeight[E ~[]T, T typedef.Integer](weights E) int {
|
||||
totalWeight := Sum(weights)
|
||||
if totalWeight <= 0 {
|
||||
return -1
|
||||
}
|
||||
|
||||
t := T(rand.Intn(int(totalWeight)))
|
||||
for i := range weights {
|
||||
if t < weights[i] {
|
||||
return i
|
||||
}
|
||||
t -= weights[i]
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func RandWeightFunc[E ~[]U, U any, T typedef.Integer](arr E, getWeight func(i int) T) int {
|
||||
weights := make([]T, 0, len(arr))
|
||||
for i := range arr {
|
||||
weights = append(weights, getWeight(i))
|
||||
}
|
||||
return RandWeight(weights)
|
||||
}
|
||||
|
||||
func Get[E ~[]T, T any, U typedef.Integer](arr E, index U) (ret T, ok bool) {
|
||||
if index < 0 || int(index) >= len(arr) {
|
||||
return
|
||||
}
|
||||
ret = arr[index]
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
|
||||
func GetPointer[E ~[]T, T any, U typedef.Integer](arr E, index U) *T {
|
||||
if index < 0 || int(index) >= len(arr) {
|
||||
return nil
|
||||
}
|
||||
return &arr[index]
|
||||
}
|
||||
|
||||
func GetFunc[E ~[]T, T any](arr E, f func(T) bool) (ret T, ok bool) {
|
||||
index := slices.IndexFunc(arr, f)
|
||||
if index < 0 {
|
||||
return
|
||||
}
|
||||
|
||||
return arr[index], true
|
||||
}
|
||||
|
||||
func GetPointerFunc[E ~[]T, T any](arr E, f func(T) bool) *T {
|
||||
index := slices.IndexFunc(arr, f)
|
||||
if index < 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &arr[index]
|
||||
}
|
||||
25
util/typedef/type.go
Normal file
25
util/typedef/type.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package typedef
|
||||
|
||||
type Signed interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64
|
||||
}
|
||||
|
||||
type Unsigned interface {
|
||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
|
||||
}
|
||||
|
||||
type Float interface {
|
||||
~float32 | ~float64
|
||||
}
|
||||
|
||||
type Integer interface {
|
||||
Signed|Unsigned
|
||||
}
|
||||
|
||||
type Number interface {
|
||||
Signed|Unsigned|Float
|
||||
}
|
||||
|
||||
type Ordered interface {
|
||||
Number|Float|~string
|
||||
}
|
||||
Reference in New Issue
Block a user