PoolAndAgent

package
v0.0.0-...-155bb80 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

PoolAndAgent project MsgPool.go

PoolAndAgent document

Index

Constants

View Source
const CHANNEL_LENGTH = 100000 //消息管道的容量
View Source
const ONPULSE_INTERVAL = 100 //LogicProcess的OnPulse函数定时调用的时间间隔,单位毫秒

Variables

This section is empty.

Functions

This section is empty.

Types

type CADODatabase

type CADODatabase struct {
	DBSourceString string      //mysql的数据库连接串	格式"root:123456@tcp(localhost:3306)/sns?charset=utf8"
	Err            error       //错误
	TheDB          *sql.DB     //数据库对象
	ReadInfo       DBReadInfo  //如果是select的读操作,相关返回结果存这里
	WriteInfo      DBWriteInfo //如果是update或insert的写操作,相关返回结果存这里
}

数据库的映射

func CreateADODatabase

func CreateADODatabase(DBSourceString string) *CADODatabase

func (*CADODatabase) GetValueByRowIdAndColName

func (this *CADODatabase) GetValueByRowIdAndColName(rowId int, colName string, value interface{}) bool

在ReadFromDB从结果集里获取数据,结果放入value中,所以value要传地址。rowId从0开始为第一行 成功返回true,失败返回false

func (*CADODatabase) InitDB

func (this *CADODatabase) InitDB()

func (*CADODatabase) ReadFromDB

func (this *CADODatabase) ReadFromDB(sqlExpress string)

从数据库里读数据

func (*CADODatabase) WriteToDB

func (this *CADODatabase) WriteToDB(sqlExpress string)

向数据库写数据

type DBReadInfo

type DBReadInfo struct {
	TheRows    *sql.Rows      //如果是读操作,这里是返回的数据集
	TheColumns map[string]int //返回的列名,key是列名,value是表示这个是第几列,在返回的时候好查找
	ArrValues  [][]string     //返回的结果值
	RowNum     int            //行数,其实就是len(ArrValues)
}

func (*DBReadInfo) Clear

func (this *DBReadInfo) Clear()

type DBWriteInfo

type DBWriteInfo struct {
	LastId       int64 //自增列的当前值
	AffectedRows int64 //写操作影响的行数
}

type ILogicProcess

type ILogicProcess interface {
	Init(myPool *SingleMsgPool) bool                       //初始化
	ProcessReq(req proto.Message, pDatabase *CADODatabase) //处理来自所绑定的SingleMsgPool发送的报文
	OnPulse(ms uint64)                                     //定时函数,每隔200ms调用一次
}

type NetAgent

type NetAgent struct {
	IpAddress string
}

func CreateNetAgent

func CreateNetAgent(ipAdd string) *NetAgent

创建一个NetAgent,ipAdd是个带端口的ip地址,如果是监听一个端口使用0.0.0.0:port NetAgent是TcpManager的映射,在CreateNetAgent并不和TcpManager联系起来,而是在SingleMsgPool的InitAndRun来创建TcpManager的TCP端口监听

func (*NetAgent) SendMsg

func (*NetAgent) SendMsg(req *bs_tcp.TCPTransferMsg)

type RouterAgent

type RouterAgent struct {
	IpAddress   string
	DialSession *DialManager.ConnectionSession
}

func CreateRouterAgent

func CreateRouterAgent(ipAdd string) *RouterAgent

func (*RouterAgent) RunRouterAgent

func (this *RouterAgent) RunRouterAgent(RouterToLogicChannel chan proto.Message, myAppId uint32, myAppType uint32)

启动运行RouterAgent

func (*RouterAgent) SendMsg

func (this *RouterAgent) SendMsg(req *bs_tcp.TCPTransferMsg)

type SingleMsgPool

type SingleMsgPool struct {
	IsInit bool
	//NetToLogicChannel如果不和服务端监听的网络层绑定,这bindingNetAgent和NetToLogicChannel两个成员变量就为空
	NetToLogicChannel chan proto.Message //网络层写,Pool层读后往逻辑层发送的消息管道

	//与router相连的网络层,bindingRouterAgent除了router app本身没有,其他app都会有,因为所有app若与其他app通信都是要靠router来转发
	RouterToLogicChannel chan proto.Message

	//ILogicProcess是一定有的,pool必须绑定,不然从网络层收来的报文就没法做业务处理了
	PoolToLogicChannel chan proto.Message //Pool层写逻辑层读的消息管道
	// contains filtered or unexported fields
}

func CreateMsgPool

func CreateMsgPool(quit chan int, myAppType uint32, myAppId uint32) *SingleMsgPool

创建一个MsgPool

func (*SingleMsgPool) AddDataBaseProcess

func (this *SingleMsgPool) AddDataBaseProcess(process *CADODatabase)

func (*SingleMsgPool) AddLogicProcess

func (this *SingleMsgPool) AddLogicProcess(agent ILogicProcess)

func (*SingleMsgPool) BindNetAgent

func (this *SingleMsgPool) BindNetAgent(agent *NetAgent)

func (*SingleMsgPool) BindRouterAgent

func (this *SingleMsgPool) BindRouterAgent(agent *RouterAgent)

func (*SingleMsgPool) InitAndRun

func (this *SingleMsgPool) InitAndRun(InitMsg proto.Message) bool

this并不是golang关键字 初始化并运行 //初始化并运行,如果bindingLogicProcesses的len大于1的话,而且需要对每个ILogicProcess都进行额外的初始化,那么InitMsg这个就是初始化报文 //比如数据库处理的pool就需要这么初始化,因为数据库的IO比较慢,所以需要多协程。 //假设我开了10个数据库协程,如果我不一开始把InitMsg推给每个ILogicProcess都处理的话,后面ILogicProcess就无法全部都初始化了 //因为10个ILogicProcess协程是共同读取同一个PoolToLogicChannel管道,所以如果像主逻辑协程那样在初始化后再发送初始化报文,那么如果连续发送10个报文 //可能是有些协程重复收到了初始化报文,有些协程没有收到初始化报文,所以一定要在go RunLogicProcess把每个协程ILogicProcess都初始化

func (*SingleMsgPool) PushMsg

func (this *SingleMsgPool) PushMsg(req proto.Message, nMs uint64)

延时nMs毫秒后推送到PoolToLogicChannel队列中

func (*SingleMsgPool) RunLogicProcess

func (this *SingleMsgPool) RunLogicProcess(pLogic ILogicProcess, pDataBase *CADODatabase, InitMsg proto.Message)

func (*SingleMsgPool) SendMsgToClientByNetAgent

func (this *SingleMsgPool) SendMsgToClientByNetAgent(req proto.Message)

func (*SingleMsgPool) SendMsgToServerAppByRouter

func (this *SingleMsgPool) SendMsgToServerAppByRouter(req proto.Message)

func (*SingleMsgPool) StopRun

func (this *SingleMsgPool) StopRun()

结束程序运行

Jump to

Keyboard shortcuts

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