1- package connection
1+ package deserver
22
33import (
44 "fmt"
@@ -10,43 +10,43 @@ import (
1010 "github.com/google/uuid"
1111)
1212
13- type ConnectionMGR struct {
14- siderInfos map [string ]* sphinxproxy.SiderInfo
15- connInfos map [string ]map [sphinxproxy.SiderType ][]* Connection
13+ type DEServerMGR struct {
14+ coinInfos map [string ]* sphinxproxy.CoinInfo
15+ connInfos map [string ]map [sphinxproxy.ClientType ][]* DEServer
1616 recvChannel sync.Map
17- connections []* Connection
17+ connections []* DEServer
1818}
1919
20- var cmgr * ConnectionMGR
20+ var cmgr * DEServerMGR
2121
22- func GetConnectionMGR () * ConnectionMGR {
22+ func GetDEServerMGR () * DEServerMGR {
2323 if cmgr == nil {
24- cmgr = & ConnectionMGR {
25- siderInfos : make (map [string ]* sphinxproxy.SiderInfo ),
26- connInfos : make (map [string ]map [sphinxproxy.SiderType ][]* Connection ),
24+ cmgr = & DEServerMGR {
25+ coinInfos : make (map [string ]* sphinxproxy.CoinInfo ),
26+ connInfos : make (map [string ]map [sphinxproxy.ClientType ][]* DEServer ),
2727 recvChannel : sync.Map {},
2828 }
2929 }
3030 return cmgr
3131}
3232
33- func (mgr * ConnectionMGR ) AddConnection (conn * Connection ) {
33+ func (mgr * DEServerMGR ) AddDEServer (conn * DEServer ) {
3434 for _ , info := range conn .Infos {
35- mgr .siderInfos [info .Name ] = info
35+ mgr .coinInfos [info .Name ] = info
3636 if _ , ok := mgr .connInfos [info .Name ]; ! ok {
37- mgr .connInfos [info .Name ] = make (map [sphinxproxy.SiderType ][]* Connection )
37+ mgr .connInfos [info .Name ] = make (map [sphinxproxy.ClientType ][]* DEServer )
3838 }
39- mgr.connInfos [info.Name ][conn.SiderType ] = append (mgr.connInfos [info.Name ][conn.SiderType ], conn )
39+ mgr.connInfos [info.Name ][conn.ClientType ] = append (mgr.connInfos [info.Name ][conn.ClientType ], conn )
4040 }
4141 mgr .connections = append (mgr .connections , conn )
4242 conn .WatchRecv (mgr .DealDataElement )
4343 conn .WatchClose (mgr .deleteConnection )
4444}
4545
46- func (mgr * ConnectionMGR ) GetConnectionInfos () []* sphinxproxy.ConnectionInfo {
47- ret := []* sphinxproxy.ConnectionInfo {}
46+ func (mgr * DEServerMGR ) GetClientInfos () []* sphinxproxy.ClientInfo {
47+ ret := []* sphinxproxy.ClientInfo {}
4848 for _ , info := range mgr .connections {
49- ret = append (ret , info .ConnectionInfo )
49+ ret = append (ret , info .ClientInfo )
5050 }
5151 return ret
5252}
@@ -58,13 +58,13 @@ type MsgInfo struct {
5858}
5959
6060// delete conn from connectionMGR
61- func (mgr * ConnectionMGR ) deleteConnection (conn * Connection ) {
61+ func (mgr * DEServerMGR ) deleteConnection (conn * DEServer ) {
6262 for _ , info := range conn .Infos {
6363 if _ , ok := mgr .connInfos [info .Name ]; ! ok {
6464 continue
6565 }
6666
67- conns , ok := mgr.connInfos [info.Name ][conn.SiderType ]
67+ conns , ok := mgr.connInfos [info.Name ][conn.ClientType ]
6868 if ! ok || len (conns ) == 0 {
6969 continue
7070 }
@@ -85,18 +85,19 @@ func (mgr *ConnectionMGR) deleteConnection(conn *Connection) {
8585 }
8686}
8787
88- func (mgr * ConnectionMGR ) CloseAll () {
88+ func (mgr * DEServerMGR ) CloseAll () {
8989 for _ , conn := range mgr .connections {
9090 conn .Close ()
9191 }
9292}
9393
9494// if recvChannel is not nil, recv response will send to it
9595// default value of statusCode is success
96- func (mgr * ConnectionMGR ) SendMsg (
96+ func (mgr * DEServerMGR ) SendMsg (
9797 name string ,
98- siderType sphinxproxy.SiderType ,
98+ clientType sphinxproxy.ClientType ,
9999 msgType sphinxproxy.MsgType ,
100+ msgID * string ,
100101 connID * string ,
101102 msg * MsgInfo ,
102103 recvChannel * chan MsgInfo ,
@@ -105,11 +106,11 @@ func (mgr *ConnectionMGR) SendMsg(
105106 return fmt .Errorf ("cannot find any sider,for %v" , name )
106107 }
107108
108- conns , ok := mgr.connInfos [name ][siderType ]
109+ conns , ok := mgr.connInfos [name ][clientType ]
109110 if ! ok || len (conns ) == 0 {
110- return fmt .Errorf ("cannot find any sider,for %v-%v" , name , siderType )
111+ return fmt .Errorf ("cannot find any sider,for %v-%v" , name , clientType )
111112 }
112- var conn * Connection
113+ var conn * DEServer
113114 if connID == nil {
114115 conn = conns [time .Now ().Second ()% len (conns )]
115116 } else {
@@ -120,22 +121,23 @@ func (mgr *ConnectionMGR) SendMsg(
120121 }
121122 }
122123 if conn == nil {
123- return fmt .Errorf ("cannot find any sider,for %v-%v-%v" , name , siderType , connID )
124+ return fmt .Errorf ("cannot find any sider,for %v-%v-%v" , name , clientType , connID )
124125 }
125126 }
126127
127- return mgr .sendMsg (msgType , nil , msg , conn , recvChannel )
128+ return mgr .sendMsg (msgType , msgID , msg , conn , recvChannel )
128129}
129130
130131// if recvChannel is not nil, recv response will send to it
131132// default value of statusCode is success
132- func (mgr * ConnectionMGR ) SendMsgWithConnID (
133+ func (mgr * DEServerMGR ) SendMsgWithConnID (
133134 msgType sphinxproxy.MsgType ,
134135 connID string ,
136+ msgID * string ,
135137 msg * MsgInfo ,
136138 recvChannel * chan MsgInfo ,
137139) error {
138- var conn * Connection
140+ var conn * DEServer
139141 for _ , _conn := range mgr .connections {
140142 if _conn .ID == connID {
141143 conn = _conn
@@ -146,16 +148,16 @@ func (mgr *ConnectionMGR) SendMsgWithConnID(
146148 return fmt .Errorf ("cannot find any sider,for %v" , connID )
147149 }
148150
149- return mgr .sendMsg (msgType , nil , msg , conn , recvChannel )
151+ return mgr .sendMsg (msgType , msgID , msg , conn , recvChannel )
150152}
151153
152154// if recvChannel is not nil, recv response will send to it
153155// default value of statusCode is success
154- func (mgr * ConnectionMGR ) sendMsg (
156+ func (mgr * DEServerMGR ) sendMsg (
155157 msgType sphinxproxy.MsgType ,
156158 msgID * string ,
157159 msg * MsgInfo ,
158- conn * Connection ,
160+ conn * DEServer ,
159161 recvChannel * chan MsgInfo ,
160162) error {
161163 if conn == nil {
@@ -188,7 +190,7 @@ func (mgr *ConnectionMGR) sendMsg(
188190 })
189191}
190192
191- func (mgr * ConnectionMGR ) DealDataElement (data * sphinxproxy.DataElement ) {
193+ func (mgr * DEServerMGR ) DealDataElement (data * sphinxproxy.DataElement ) {
192194 if ch , ok := mgr .recvChannel .LoadAndDelete (data .MsgID ); ok {
193195 select {
194196 case <- time .NewTimer (time .Second ).C :
0 commit comments