mirror of
https://github.com/duanhf2012/origin.git
synced 2026-06-11 07:46:50 +08:00
优化代码规范
This commit is contained in:
@@ -3,20 +3,21 @@ package rpc
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"github.com/duanhf2012/origin/v2/log"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
"github.com/duanhf2012/origin/v2/event"
|
||||
"time"
|
||||
)
|
||||
|
||||
const maxClusterNode int = 32
|
||||
|
||||
type FuncRpcClient func(nodeId string, serviceMethod string,filterRetire bool, client []*Client) (error, []*Client)
|
||||
type FuncRpcClient func(nodeId string, serviceMethod string, filterRetire bool, client []*Client) (error, []*Client)
|
||||
type FuncRpcServer func() IServer
|
||||
|
||||
const NodeIdNull = ""
|
||||
|
||||
var nilError = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem())
|
||||
@@ -47,7 +48,7 @@ type RpcMethodInfo struct {
|
||||
rpcProcessorType RpcProcessorType
|
||||
}
|
||||
|
||||
type RawRpcCallBack func(rawData []byte)
|
||||
type RawRpcCallBack func(rawData []byte)
|
||||
|
||||
type IRpcHandlerChannel interface {
|
||||
PushRpcResponse(call *Call) error
|
||||
@@ -66,7 +67,7 @@ type RpcHandler struct {
|
||||
//pClientList []*Client
|
||||
}
|
||||
|
||||
//type TriggerRpcConnEvent func(bConnect bool, clientSeq uint32, nodeId string)
|
||||
// NotifyEventToAllService type TriggerRpcConnEvent func(bConnect bool, clientSeq uint32, nodeId string)
|
||||
type NotifyEventToAllService func(event event.IEvent)
|
||||
|
||||
type INodeConnListener interface {
|
||||
@@ -85,7 +86,8 @@ type IDiscoveryServiceListener interface {
|
||||
}
|
||||
|
||||
type CancelRpc func()
|
||||
func emptyCancelRpc(){}
|
||||
|
||||
func emptyCancelRpc() {}
|
||||
|
||||
type IRpcHandler interface {
|
||||
IRpcHandlerChannel
|
||||
@@ -94,17 +96,17 @@ type IRpcHandler interface {
|
||||
GetRpcHandler() IRpcHandler
|
||||
HandlerRpcRequest(request *RpcRequest)
|
||||
HandlerRpcResponseCB(call *Call)
|
||||
CallMethod(client *Client,ServiceMethod string, param interface{},callBack reflect.Value, reply interface{}) error
|
||||
CallMethod(client *Client, ServiceMethod string, param interface{}, callBack reflect.Value, reply interface{}) error
|
||||
|
||||
Call(serviceMethod string, args interface{}, reply interface{}) error
|
||||
CallNode(nodeId string, serviceMethod string, args interface{}, reply interface{}) error
|
||||
AsyncCall(serviceMethod string, args interface{}, callback interface{}) error
|
||||
AsyncCallNode(nodeId string, serviceMethod string, args interface{}, callback interface{}) error
|
||||
|
||||
CallWithTimeout(timeout time.Duration,serviceMethod string, args interface{}, reply interface{}) error
|
||||
CallNodeWithTimeout(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, reply interface{}) error
|
||||
AsyncCallWithTimeout(timeout time.Duration,serviceMethod string, args interface{}, callback interface{}) (CancelRpc,error)
|
||||
AsyncCallNodeWithTimeout(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, callback interface{}) (CancelRpc,error)
|
||||
CallWithTimeout(timeout time.Duration, serviceMethod string, args interface{}, reply interface{}) error
|
||||
CallNodeWithTimeout(timeout time.Duration, nodeId string, serviceMethod string, args interface{}, reply interface{}) error
|
||||
AsyncCallWithTimeout(timeout time.Duration, serviceMethod string, args interface{}, callback interface{}) (CancelRpc, error)
|
||||
AsyncCallNodeWithTimeout(timeout time.Duration, nodeId string, serviceMethod string, args interface{}, callback interface{}) (CancelRpc, error)
|
||||
|
||||
Go(serviceMethod string, args interface{}) error
|
||||
GoNode(nodeId string, serviceMethod string, args interface{}) error
|
||||
@@ -221,7 +223,7 @@ func (handler *RpcHandler) HandlerRpcResponseCB(call *Call) {
|
||||
buf := make([]byte, 4096)
|
||||
l := runtime.Stack(buf, false)
|
||||
errString := fmt.Sprint(r)
|
||||
log.Dump(string(buf[:l]),log.String("error",errString))
|
||||
log.Dump(string(buf[:l]), log.String("error", errString))
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -243,7 +245,7 @@ func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
|
||||
buf := make([]byte, 4096)
|
||||
l := runtime.Stack(buf, false)
|
||||
errString := fmt.Sprint(r)
|
||||
log.Dump(string(buf[:l]),log.String("error",errString))
|
||||
log.Dump(string(buf[:l]), log.String("error", errString))
|
||||
rpcErr := RpcError("call error : core dumps")
|
||||
if request.requestHandle != nil {
|
||||
request.requestHandle(nil, rpcErr)
|
||||
@@ -256,12 +258,12 @@ func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
|
||||
if rawRpcId > 0 {
|
||||
v, ok := handler.mapRawFunctions[rawRpcId]
|
||||
if ok == false {
|
||||
log.Error("RpcHandler cannot find request rpc id",log.Uint32("rawRpcId",rawRpcId))
|
||||
log.Error("RpcHandler cannot find request rpc id", log.Uint32("rawRpcId", rawRpcId))
|
||||
return
|
||||
}
|
||||
rawData,ok := request.inParam.([]byte)
|
||||
rawData, ok := request.inParam.([]byte)
|
||||
if ok == false {
|
||||
log.Error("RpcHandler cannot convert",log.String("RpcHandlerName",handler.rpcHandler.GetName()),log.Uint32("rawRpcId",rawRpcId))
|
||||
log.Error("RpcHandler cannot convert", log.String("RpcHandlerName", handler.rpcHandler.GetName()), log.Uint32("rawRpcId", rawRpcId))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -273,7 +275,7 @@ func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
|
||||
v, ok := handler.mapFunctions[request.RpcRequestData.GetServiceMethod()]
|
||||
if ok == false {
|
||||
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()))
|
||||
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))
|
||||
}
|
||||
@@ -304,29 +306,29 @@ func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
|
||||
paramList = append(paramList, oParam) //输出参数
|
||||
} else if request.requestHandle != nil && v.hasResponder == false { //调用方有返回值,但被调用函数没有返回参数
|
||||
rErr := "Call Rpc " + request.RpcRequestData.GetServiceMethod() + " without return parameter!"
|
||||
log.Error("call serviceMethod without return parameter",log.String("serviceMethod",request.RpcRequestData.GetServiceMethod()))
|
||||
log.Error("call serviceMethod without return parameter", log.String("serviceMethod", request.RpcRequestData.GetServiceMethod()))
|
||||
request.requestHandle(nil, RpcError(rErr))
|
||||
return
|
||||
}
|
||||
|
||||
requestHanle := request.requestHandle
|
||||
requestHandle := request.requestHandle
|
||||
returnValues := v.method.Func.Call(paramList)
|
||||
errInter := returnValues[0].Interface()
|
||||
if errInter != nil {
|
||||
err = errInter.(error)
|
||||
}
|
||||
|
||||
if v.hasResponder == false && requestHanle != nil {
|
||||
requestHanle(oParam.Interface(), ConvertError(err))
|
||||
if v.hasResponder == false && requestHandle != nil {
|
||||
requestHandle(oParam.Interface(), ConvertError(err))
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) CallMethod(client *Client,ServiceMethod string, param interface{},callBack reflect.Value, reply interface{}) error {
|
||||
func (handler *RpcHandler) CallMethod(client *Client, ServiceMethod string, param interface{}, callBack reflect.Value, reply interface{}) error {
|
||||
var err error
|
||||
v, ok := handler.mapFunctions[ServiceMethod]
|
||||
if ok == false {
|
||||
err = errors.New("RpcHandler " + handler.rpcHandler.GetName() + " cannot find" + ServiceMethod)
|
||||
log.Error("CallMethod cannot find serviceMethod",log.String("rpcHandlerName",handler.rpcHandler.GetName()),log.String("serviceMethod",ServiceMethod))
|
||||
log.Error("CallMethod cannot find serviceMethod", log.String("rpcHandlerName", handler.rpcHandler.GetName()), log.String("serviceMethod", ServiceMethod))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -347,31 +349,31 @@ func (handler *RpcHandler) CallMethod(client *Client,ServiceMethod string, param
|
||||
//有返回值时
|
||||
if reply != nil {
|
||||
//如果是Call同步调用
|
||||
hander :=func(Returns interface{}, Err RpcError) {
|
||||
hd := func(Returns interface{}, Err RpcError) {
|
||||
rpcCall := client.RemovePending(callSeq)
|
||||
if rpcCall == nil {
|
||||
log.Error("cannot find call seq",log.Uint64("seq",callSeq))
|
||||
log.Error("cannot find call seq", log.Uint64("seq", callSeq))
|
||||
return
|
||||
}
|
||||
|
||||
//解析数据
|
||||
if len(Err)!=0 {
|
||||
if len(Err) != 0 {
|
||||
rpcCall.Err = Err
|
||||
}else if Returns != nil {
|
||||
} else if Returns != nil {
|
||||
_, processor := GetProcessorType(Returns)
|
||||
var bytes []byte
|
||||
bytes,rpcCall.Err = processor.Marshal(Returns)
|
||||
bytes, rpcCall.Err = processor.Marshal(Returns)
|
||||
if rpcCall.Err == nil {
|
||||
rpcCall.Err = processor.Unmarshal(bytes,reply)
|
||||
rpcCall.Err = processor.Unmarshal(bytes, reply)
|
||||
}
|
||||
}
|
||||
|
||||
//如果找不到,说明已经超时
|
||||
rpcCall.Reply = reply
|
||||
rpcCall.done<-rpcCall
|
||||
rpcCall.done <- rpcCall
|
||||
}
|
||||
paramList = append(paramList, reflect.ValueOf(hander))
|
||||
}else{//无返回值时,是一个requestHandlerNull空回调
|
||||
paramList = append(paramList, reflect.ValueOf(hd))
|
||||
} else { //无返回值时,是一个requestHandlerNull空回调
|
||||
paramList = append(paramList, callBack)
|
||||
}
|
||||
paramList = append(paramList, reflect.ValueOf(param))
|
||||
@@ -381,11 +383,11 @@ func (handler *RpcHandler) CallMethod(client *Client,ServiceMethod string, param
|
||||
|
||||
//判断返回值是否错误,有错误时则回调
|
||||
errInter := returnValues[0].Interface()
|
||||
if errInter != nil && callBack!=requestHandlerNull{
|
||||
if errInter != nil && callBack != requestHandlerNull {
|
||||
err = errInter.(error)
|
||||
callBack.Call([]reflect.Value{reflect.ValueOf(reply), reflect.ValueOf(err)})
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
paramList = append(paramList, reflect.ValueOf(handler.GetRpcHandler())) //接受者
|
||||
paramList = append(paramList, reflect.ValueOf(param))
|
||||
|
||||
@@ -394,7 +396,7 @@ func (handler *RpcHandler) CallMethod(client *Client,ServiceMethod string, param
|
||||
//不带返回值参数的RPC函数
|
||||
if reply == nil {
|
||||
paramList = append(paramList, reflect.New(v.outParamValue.Type().Elem()))
|
||||
}else{
|
||||
} else {
|
||||
//带返回值参数的RPC函数
|
||||
paramList = append(paramList, reflect.ValueOf(reply)) //输出参数
|
||||
}
|
||||
@@ -411,14 +413,14 @@ func (handler *RpcHandler) CallMethod(client *Client,ServiceMethod string, param
|
||||
valErr = reflect.ValueOf(err)
|
||||
}
|
||||
|
||||
callBack.Call([]reflect.Value{reflect.ValueOf(reply),valErr })
|
||||
callBack.Call([]reflect.Value{reflect.ValueOf(reply), valErr})
|
||||
}
|
||||
}
|
||||
|
||||
rpcCall := client.FindPending(callSeq)
|
||||
if rpcCall!=nil {
|
||||
err = rpcCall.Done().Err
|
||||
if rpcCall.callback!= nil {
|
||||
if rpcCall != nil {
|
||||
err = rpcCall.Done().Err
|
||||
if rpcCall.callback != nil {
|
||||
valErr := nilError
|
||||
if rpcCall.Err != nil {
|
||||
valErr = reflect.ValueOf(rpcCall.Err)
|
||||
@@ -433,25 +435,25 @@ func (handler *RpcHandler) CallMethod(client *Client,ServiceMethod string, param
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId string, serviceMethod string, args interface{}) error {
|
||||
pClientList :=make([]*Client,0,maxClusterNode)
|
||||
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList)
|
||||
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))
|
||||
log.Error("call serviceMethod is failed", log.String("serviceMethod", serviceMethod), log.ErrorAttr("error", err))
|
||||
} else {
|
||||
log.Error("cannot find serviceMethod",log.String("serviceMethod",serviceMethod))
|
||||
log.Error("cannot find serviceMethod", log.String("serviceMethod", serviceMethod))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if len(pClientList) > 1 && bCast == false {
|
||||
log.Error("cannot call serviceMethod more then 1 node",log.String("serviceMethod",serviceMethod))
|
||||
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 < len(pClientList); i++ {
|
||||
pCall := pClientList[i].Go(pClientList[i].GetTargetNodeId(),DefaultRpcTimeout,handler.rpcHandler,true, serviceMethod, args, nil)
|
||||
pCall := pClientList[i].Go(pClientList[i].GetTargetNodeId(), DefaultRpcTimeout, handler.rpcHandler, true, serviceMethod, args, nil)
|
||||
if pCall.Err != nil {
|
||||
err = pCall.Err
|
||||
}
|
||||
@@ -462,23 +464,23 @@ func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId str
|
||||
return err
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) callRpc(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, reply interface{}) error {
|
||||
pClientList :=make([]*Client,0,maxClusterNode)
|
||||
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList)
|
||||
func (handler *RpcHandler) callRpc(timeout time.Duration, nodeId string, serviceMethod string, args interface{}, reply interface{}) error {
|
||||
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))
|
||||
log.Error("Call serviceMethod is failed", log.ErrorAttr("error", err))
|
||||
return err
|
||||
} else if len(pClientList) <= 0 {
|
||||
err = errors.New("Call serviceMethod is error:cannot find " + serviceMethod)
|
||||
log.Error("cannot find serviceMethod",log.String("serviceMethod",serviceMethod))
|
||||
log.Error("cannot find serviceMethod", log.String("serviceMethod", serviceMethod))
|
||||
return err
|
||||
} else if len(pClientList) > 1 {
|
||||
log.Error("Cannot call more then 1 node!",log.String("serviceMethod",serviceMethod))
|
||||
log.Error("Cannot call more then 1 node!", log.String("serviceMethod", serviceMethod))
|
||||
return errors.New("cannot call more then 1 node")
|
||||
}
|
||||
|
||||
pClient := pClientList[0]
|
||||
pCall := pClient.Go(pClient.GetTargetNodeId(),timeout,handler.rpcHandler,false, serviceMethod, args, reply)
|
||||
pCall := pClient.Go(pClient.GetTargetNodeId(), timeout, handler.rpcHandler, false, serviceMethod, args, reply)
|
||||
|
||||
err = pCall.Done().Err
|
||||
pClient.RemovePending(pCall.Seq)
|
||||
@@ -486,81 +488,81 @@ func (handler *RpcHandler) callRpc(timeout time.Duration,nodeId string, serviceM
|
||||
return err
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) asyncCallRpc(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, callback interface{}) (CancelRpc,error) {
|
||||
func (handler *RpcHandler) asyncCallRpc(timeout time.Duration, nodeId string, serviceMethod string, args interface{}, callback interface{}) (CancelRpc, error) {
|
||||
fVal := reflect.ValueOf(callback)
|
||||
if fVal.Kind() != reflect.Func {
|
||||
err := errors.New("call " + serviceMethod + " input callback param is error!")
|
||||
log.Error("input callback param is error",log.String("serviceMethod",serviceMethod))
|
||||
return emptyCancelRpc,err
|
||||
log.Error("input callback param is error", log.String("serviceMethod", serviceMethod))
|
||||
return emptyCancelRpc, err
|
||||
}
|
||||
|
||||
if fVal.Type().NumIn() != 2 {
|
||||
err := errors.New("call " + serviceMethod + " callback param function is error!")
|
||||
log.Error("callback param function is error",log.String("serviceMethod",serviceMethod))
|
||||
return emptyCancelRpc,err
|
||||
log.Error("callback param function is error", log.String("serviceMethod", serviceMethod))
|
||||
return emptyCancelRpc, err
|
||||
}
|
||||
|
||||
if fVal.Type().In(0).Kind() != reflect.Ptr || fVal.Type().In(1).String() != "error" {
|
||||
err := errors.New("call " + serviceMethod + " callback param function is error!")
|
||||
log.Error("callback param function is error",log.String("serviceMethod",serviceMethod))
|
||||
return emptyCancelRpc,err
|
||||
log.Error("callback param function is error", log.String("serviceMethod", serviceMethod))
|
||||
return emptyCancelRpc, err
|
||||
}
|
||||
|
||||
reply := reflect.New(fVal.Type().In(0).Elem()).Interface()
|
||||
pClientList :=make([]*Client,0,1)
|
||||
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
||||
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)
|
||||
}else {
|
||||
err = fmt.Errorf("No %s service found in the origin network",serviceMethod)
|
||||
if nodeId != NodeIdNull {
|
||||
err = fmt.Errorf("cannot find %s from nodeId %s", serviceMethod, nodeId)
|
||||
} else {
|
||||
err = fmt.Errorf("no %s service found in the origin network", serviceMethod)
|
||||
}
|
||||
}
|
||||
fVal.Call([]reflect.Value{reflect.ValueOf(reply), reflect.ValueOf(err)})
|
||||
log.Error("cannot find serviceMethod from node",log.String("serviceMethod",serviceMethod),log.String("nodeId",nodeId))
|
||||
return emptyCancelRpc,nil
|
||||
log.Error("cannot find serviceMethod from node", log.String("serviceMethod", serviceMethod), log.String("nodeId", nodeId))
|
||||
return emptyCancelRpc, nil
|
||||
}
|
||||
|
||||
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))
|
||||
return emptyCancelRpc,nil
|
||||
log.Error("cannot call more then 1 node", log.String("serviceMethod", serviceMethod))
|
||||
return emptyCancelRpc, nil
|
||||
}
|
||||
|
||||
//2.rpcClient调用
|
||||
//如果调用本结点服务
|
||||
return pClientList[0].AsyncCall(pClientList[0].GetTargetNodeId(),timeout,handler.rpcHandler, serviceMethod, fVal, args, reply,false)
|
||||
return pClientList[0].AsyncCall(pClientList[0].GetTargetNodeId(), timeout, handler.rpcHandler, serviceMethod, fVal, args, reply, false)
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) GetName() string {
|
||||
return handler.rpcHandler.GetName()
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) CallWithTimeout(timeout time.Duration,serviceMethod string, args interface{}, reply interface{}) error {
|
||||
return handler.callRpc(timeout,NodeIdNull, serviceMethod, args, reply)
|
||||
func (handler *RpcHandler) CallWithTimeout(timeout time.Duration, serviceMethod string, args interface{}, reply interface{}) error {
|
||||
return handler.callRpc(timeout, NodeIdNull, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) CallNodeWithTimeout(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, reply interface{}) error{
|
||||
return handler.callRpc(timeout,nodeId, serviceMethod, args, reply)
|
||||
func (handler *RpcHandler) CallNodeWithTimeout(timeout time.Duration, nodeId string, serviceMethod string, args interface{}, reply interface{}) error {
|
||||
return handler.callRpc(timeout, nodeId, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) AsyncCallWithTimeout(timeout time.Duration,serviceMethod string, args interface{}, callback interface{}) (CancelRpc,error){
|
||||
return handler.asyncCallRpc(timeout,NodeIdNull, serviceMethod, args, callback)
|
||||
func (handler *RpcHandler) AsyncCallWithTimeout(timeout time.Duration, serviceMethod string, args interface{}, callback interface{}) (CancelRpc, error) {
|
||||
return handler.asyncCallRpc(timeout, NodeIdNull, serviceMethod, args, callback)
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) AsyncCallNodeWithTimeout(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, callback interface{}) (CancelRpc,error){
|
||||
return handler.asyncCallRpc(timeout,nodeId, serviceMethod, args, callback)
|
||||
func (handler *RpcHandler) AsyncCallNodeWithTimeout(timeout time.Duration, nodeId string, serviceMethod string, args interface{}, callback interface{}) (CancelRpc, error) {
|
||||
return handler.asyncCallRpc(timeout, nodeId, serviceMethod, args, callback)
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) AsyncCall(serviceMethod string, args interface{}, callback interface{}) error {
|
||||
_,err := handler.asyncCallRpc(DefaultRpcTimeout,NodeIdNull, serviceMethod, args, callback)
|
||||
_, err := handler.asyncCallRpc(DefaultRpcTimeout, NodeIdNull, serviceMethod, args, callback)
|
||||
return err
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
return handler.callRpc(DefaultRpcTimeout,NodeIdNull, serviceMethod, args, reply)
|
||||
return handler.callRpc(DefaultRpcTimeout, NodeIdNull, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) Go(serviceMethod string, args interface{}) error {
|
||||
@@ -568,13 +570,13 @@ func (handler *RpcHandler) Go(serviceMethod string, args interface{}) error {
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) AsyncCallNode(nodeId string, serviceMethod string, args interface{}, callback interface{}) error {
|
||||
_,err:= handler.asyncCallRpc(DefaultRpcTimeout,nodeId, serviceMethod, args, callback)
|
||||
_, err := handler.asyncCallRpc(DefaultRpcTimeout, nodeId, serviceMethod, args, callback)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) CallNode(nodeId string, serviceMethod string, args interface{}, reply interface{}) error {
|
||||
return handler.callRpc(DefaultRpcTimeout,nodeId, serviceMethod, args, reply)
|
||||
return handler.callRpc(DefaultRpcTimeout, nodeId, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
func (handler *RpcHandler) GoNode(nodeId string, serviceMethod string, args interface{}) error {
|
||||
@@ -587,15 +589,15 @@ 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))
|
||||
pClientList := make([]*Client,0,1)
|
||||
err, pClientList := handler.funcRpcClient(nodeId, serviceName,false, pClientList)
|
||||
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))
|
||||
log.Error("call serviceMethod is failed", log.ErrorAttr("error", err))
|
||||
return err
|
||||
}
|
||||
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))
|
||||
log.Error("cannot call more then 1 node", log.String("serviceName", serviceName))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -603,7 +605,7 @@ func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType, nodeId s
|
||||
//如果调用本结点服务
|
||||
for i := 0; i < len(pClientList); i++ {
|
||||
//跨node调用
|
||||
pCall := pClientList[i].RawGo(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
|
||||
}
|
||||
@@ -621,7 +623,7 @@ func (handler *RpcHandler) RegRawRpc(rpcMethodId uint32, rawRpcCB RawRpcCallBack
|
||||
|
||||
func (handler *RpcHandler) UnmarshalInParam(rpcProcessor IRpcProcessor, serviceMethod string, rawRpcMethodId uint32, inParam []byte) (interface{}, error) {
|
||||
if rawRpcMethodId > 0 {
|
||||
return inParam,nil
|
||||
return inParam, nil
|
||||
}
|
||||
|
||||
v, ok := handler.mapFunctions[serviceMethod]
|
||||
@@ -635,7 +637,6 @@ func (handler *RpcHandler) UnmarshalInParam(rpcProcessor IRpcProcessor, serviceM
|
||||
return param, err
|
||||
}
|
||||
|
||||
|
||||
func (handler *RpcHandler) GetRpcServer() FuncRpcServer{
|
||||
func (handler *RpcHandler) GetRpcServer() FuncRpcServer {
|
||||
return handler.funcRpcServer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user