in protocol/triple/triple_invoker.go [64:143]
func (ti *TripleInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
var result protocol.RPCResult
if !ti.BaseInvoker.IsAvailable() {
// Generally, the case will not happen, because the invoker has been removed
// from the invoker list before destroy,so no new request will enter the destroyed invoker
logger.Warnf("TripleInvoker is destroyed")
result.SetError(protocol.ErrDestroyedInvoker)
return &result
}
ti.clientGuard.RLock()
defer ti.clientGuard.RUnlock()
if ti.clientManager == nil {
result.SetError(protocol.ErrClientClosed)
return &result
}
callType, inRaw, method, err := parseInvocation(ctx, ti.GetURL(), invocation)
if err != nil {
result.SetError(err)
return &result
}
ctx, err = mergeAttachmentToOutgoing(ctx, invocation)
if err != nil {
result.SetError(err)
return &result
}
inRawLen := len(inRaw)
if !ti.clientManager.isIDL {
switch callType {
case constant.CallUnary:
// todo(DMwangnima): consider inRawLen == 0
if err := ti.clientManager.callUnary(ctx, method, inRaw[0:inRawLen-1], inRaw[inRawLen-1]); err != nil {
result.SetError(err)
}
default:
panic("Triple only supports Unary Invocation for Non-IDL mode")
}
return &result
}
switch callType {
case constant.CallUnary:
if len(inRaw) != 2 {
panic(fmt.Sprintf("Wrong parameter Values number for CallUnary, want 2, but got %d", inRawLen))
}
if err := ti.clientManager.callUnary(ctx, method, inRaw[0], inRaw[1]); err != nil {
result.SetError(err)
}
case constant.CallClientStream:
stream, err := ti.clientManager.callClientStream(ctx, method)
if err != nil {
result.SetError(err)
}
result.SetResult(stream)
case constant.CallServerStream:
if inRawLen != 1 {
panic(fmt.Sprintf("Wrong parameter Values number for CallServerStream, want 1, but got %d", inRawLen))
}
stream, err := ti.clientManager.callServerStream(ctx, method, inRaw[0])
if err != nil {
result.Err = err
}
result.SetResult(stream)
case constant.CallBidiStream:
stream, err := ti.clientManager.callBidiStream(ctx, method)
if err != nil {
result.Err = err
}
result.SetResult(stream)
default:
panic(fmt.Sprintf("Unsupported CallType: %s", callType))
}
return &result
}