Blame view

common/components/icompontents.go 2.77 KB
0e5d52de   zhangqijia   reactor: 重构底层框架1.0
1
2
  package components
  
765431a4   zhangqijia   增加schema接口, 抽象 mo...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  //-----------------
  //----net start----
  //-----------------
  type (
  	//网络包头
  	IHead interface {
  		GetDataLen() uint32  //获取消息数据段长度
  		GetMsgID() uint32    //获取消息ID
  		GetErrCode() int32   //获取消息错误码
  		GetPreserve() uint32 //获取预留数据
  	}
  	//网络包
  	IMessage interface {
  		IHead
  		GetHeader() IHead       //获取消息头
  		SetHeader(header IHead) //设置消息头
  
  		GetData() []byte //获取消息内容
  		SetData([]byte)  //设置消息内容
  
  		SetSession(IConnection)  //设置连接
  		GetSession() IConnection //获取连接
  	}
  	//网络拆包解包器
  	ISplitter interface {
  		UnPack([]byte) (IMessage, error)
  		Pack(cmd uint32, data []byte, errcode int32, preserve uint32) ([]byte, error)
  		ParseMsg(data []byte, atEOF bool) (advance int, token []byte, err error)
  		GetHeadLen() uint32
  	}
  	ConnectionCallback func(IConnection)
  	CloseCallback      func(IConnection)
  	MessageCallback    func(IMessage)
  	TimerCallback      func(IConnection)
  	//链接
  	IConnection interface {
58e37bfe   zhangqijia   add sync.Pool to ...
39
  		GetID() uint32
765431a4   zhangqijia   增加schema接口, 抽象 mo...
40
41
42
43
44
45
46
47
48
  		Start()
  		Stop()
  		Send(code int32, cmd uint32, b []byte) error
  
  		SetConnectionCallback(ConnectionCallback)
  		SetMessageCallback(MessageCallback)
  		SetCloseCallback(CloseCallback)
  		SetTimerCallback(TimerCallback)
  	}
cd2f96ab   zhangqijia   fix: 优化连接管理
49
50
  	//connManage
  	IConnManage interface {
58e37bfe   zhangqijia   add sync.Pool to ...
51
52
53
  		AddConn(id uint32, connection IConnection)
  		GetConn(id uint32) IConnection
  		DelConn(id uint32) IConnection
cd2f96ab   zhangqijia   fix: 优化连接管理
54
55
56
  		Range(f func(key interface{}, value interface{}) bool)
  		StopAllConns()
  	}
765431a4   zhangqijia   增加schema接口, 抽象 mo...
57
58
59
60
61
62
  	//server
  	IServer interface {
  		Start() error
  		Stop()
  
  		GetSplitter() ISplitter
765431a4   zhangqijia   增加schema接口, 抽象 mo...
63
64
  		GetPlugin() IPlugin
  		GetAction(uint32) interface{}
69d286a7   zhangqijia   fix: 插件用来做部分热更
65
  		SetActions(map[interface{}]interface{})
cd2f96ab   zhangqijia   fix: 优化连接管理
66
  		GetConnManage() IConnManage
765431a4   zhangqijia   增加schema接口, 抽象 mo...
67
68
69
70
71
72
73
74
75
76
77
78
79
  
  		SetConnectionCallback(ConnectionCallback)
  		SetMessageCallback(MessageCallback)
  		SetCloseCallback(CloseCallback)
  		SetTimerCallback(TimerCallback)
  	}
  
  	//httpserver
  	IHttp interface {
  		Start() error
  		Stop()
  		BindHandler(interface{})
  	}
69d286a7   zhangqijia   fix: 插件用来做部分热更
80
  	ActionHandler func(msg IMessage) (int32, interface{})
765431a4   zhangqijia   增加schema接口, 抽象 mo...
81
82
83
84
85
86
  	//用于热更逻辑的插件接口
  	IPlugin interface {
  		LoadPlugin() error
  		SetActions(map[interface{}]interface{})
  		GetAction(uint32) interface{}
  	}
765431a4   zhangqijia   增加schema接口, 抽象 mo...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  )
  
  //-----------------
  //-----db start----
  //-----------------
  type (
  	IDB interface {
  		CreateTable() error
  
  		Create() (interface{}, error)
  		Load() error
  		FindOne() error
  		UpdateProperty(key string, val interface{}) error
  		UpdateProperties(properties map[string]interface{}) error
  
  		SetUnique(key string) (string, error)
  	}
  
  	ISchema interface {
  		Init()
  		GetDB() IDB
  
  		GetPri() interface{}
  		GetSchema() interface{}
  		GetSchemaName() string
  
  		Load() error
  		Create() error
  		Update()
  
  		SetProperty(key string, val interface{})
  		SetProperties(properties map[string]interface{})
  	}
  )
  
  //-----------------
  //-----db end------
  //-----------------