mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化协议解析器和服务接口
This commit is contained in:
@@ -411,13 +411,13 @@ func GetNodeByServiceName(serviceName string) map[string]struct{} {
|
|||||||
return mapNodeId
|
return mapNodeId
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNodeByTemplateServiceName 通过模板服务名获取服务名,返回 map[serviceName真实服务名]NodeId
|
// GetNodeByTemplateServiceName 通过模板服务名获取服务名,返回 map[serviceName真实服务名][]NodeId
|
||||||
func GetNodeByTemplateServiceName(templateServiceName string) map[string]string {
|
func GetNodeByTemplateServiceName(templateServiceName string) map[string][]string {
|
||||||
cluster.locker.RLock()
|
cluster.locker.RLock()
|
||||||
defer cluster.locker.RUnlock()
|
defer cluster.locker.RUnlock()
|
||||||
|
|
||||||
mapServiceName := cluster.mapTemplateServiceNode[templateServiceName]
|
mapServiceName := cluster.mapTemplateServiceNode[templateServiceName]
|
||||||
mapNodeId := make(map[string]string, 9)
|
mapNodeId := make(map[string][]string, 9)
|
||||||
for serviceName := range mapServiceName {
|
for serviceName := range mapServiceName {
|
||||||
mapNode, ok := cluster.mapServiceNode[serviceName]
|
mapNode, ok := cluster.mapServiceNode[serviceName]
|
||||||
if ok == false {
|
if ok == false {
|
||||||
@@ -425,7 +425,9 @@ func GetNodeByTemplateServiceName(templateServiceName string) map[string]string
|
|||||||
}
|
}
|
||||||
|
|
||||||
for nodeId := range mapNode {
|
for nodeId := range mapNode {
|
||||||
mapNodeId[serviceName] = nodeId
|
nodes := mapNodeId[serviceName]
|
||||||
|
nodes = append(nodes, nodeId)
|
||||||
|
mapNodeId[serviceName] = nodes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type RawMessageInfo struct {
|
|||||||
msgHandler RawMessageHandler
|
msgHandler RawMessageHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
type RawMessageHandler func(clientId string, packType uint16, msg []byte)
|
type RawMessageHandler func(clientId string, packType uint16,additionData any, msg []byte)
|
||||||
type RawConnectHandler func(clientId string)
|
type RawConnectHandler func(clientId string)
|
||||||
type UnknownRawMessageHandler func(clientId string, msg []byte)
|
type UnknownRawMessageHandler func(clientId string, msg []byte)
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ func (pbRawProcessor *PBRawProcessor) SetByteOrder(littleEndian bool) {
|
|||||||
// MsgRoute must goroutine safe
|
// MsgRoute must goroutine safe
|
||||||
func (pbRawProcessor *PBRawProcessor) MsgRoute(clientId string, msg interface{}, recyclerReaderBytes func(data []byte)) error {
|
func (pbRawProcessor *PBRawProcessor) MsgRoute(clientId string, msg interface{}, recyclerReaderBytes func(data []byte)) error {
|
||||||
pPackInfo := msg.(*PBRawPackInfo)
|
pPackInfo := msg.(*PBRawPackInfo)
|
||||||
pbRawProcessor.msgHandler(clientId, pPackInfo.typ, pPackInfo.rawMsg)
|
pbRawProcessor.msgHandler(clientId, pPackInfo.typ, nil, pPackInfo.rawMsg)
|
||||||
recyclerReaderBytes(pPackInfo.rawMsg)
|
recyclerReaderBytes(pPackInfo.rawMsg)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ type IRawProcessor interface {
|
|||||||
|
|
||||||
SetByteOrder(littleEndian bool)
|
SetByteOrder(littleEndian bool)
|
||||||
SetRawMsgHandler(handle RawMessageHandler)
|
SetRawMsgHandler(handle RawMessageHandler)
|
||||||
MakeRawMsg(msgType uint16, msg []byte, pbRawPackInfo *PBRawPackInfo)
|
|
||||||
SetUnknownMsgHandler(unknownMessageHandler UnknownRawMessageHandler)
|
SetUnknownMsgHandler(unknownMessageHandler UnknownRawMessageHandler)
|
||||||
SetConnectedHandler(connectHandler RawConnectHandler)
|
SetConnectedHandler(connectHandler RawConnectHandler)
|
||||||
SetDisConnectedHandler(disconnectHandler RawConnectHandler)
|
SetDisConnectedHandler(disconnectHandler RawConnectHandler)
|
||||||
|
|||||||
Reference in New Issue
Block a user