/// <exception cref="System.Exception"/> public virtual object Invoke(object proxy, MethodInfo method, object[] args) { long startTime = 0; if (Log.IsDebugEnabled()) { startTime = Time.Now(); } TraceScope traceScope = null; if (Trace.IsTracing()) { traceScope = Trace.StartSpan(RpcClientUtil.MethodToTraceString(method)); } ObjectWritable value; try { value = (ObjectWritable)client.Call(RPC.RpcKind.RpcWritable, new WritableRpcEngine.Invocation (method, args), remoteId, fallbackToSimpleAuth); } finally { if (traceScope != null) { traceScope.Close(); } } if (Log.IsDebugEnabled()) { long callTime = Time.Now() - startTime; Log.Debug("Call: " + method.Name + " " + callTime); } return(value.Get()); }
/// <summary>This is the client side invoker of RPC method.</summary> /// <remarks> /// This is the client side invoker of RPC method. It only throws /// ServiceException, since the invocation proxy expects only /// ServiceException to be thrown by the method in case protobuf service. /// ServiceException has the following causes: /// <ol> /// <li>Exceptions encountered on the client side in this method are /// set as cause in ServiceException as is.</li> /// <li>Exceptions from the server are wrapped in RemoteException and are /// set as cause in ServiceException</li> /// </ol> /// Note that the client calling protobuf RPC methods, must handle /// ServiceException by getting the cause from the ServiceException. If the /// cause is RemoteException, then unwrap it to get the exception thrown by /// the server. /// </remarks> /// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual object Invoke(object proxy, MethodInfo method, object[] args) { long startTime = 0; if (Log.IsDebugEnabled()) { startTime = Time.Now(); } if (args.Length != 2) { // RpcController + Message throw new ServiceException("Too many parameters for request. Method: [" + method. Name + "]" + ", Expected: 2, Actual: " + args.Length); } if (args[1] == null) { throw new ServiceException("null param while calling Method: [" + method.Name + "]" ); } TraceScope traceScope = null; // if Tracing is on then start a new span for this rpc. // guard it in the if statement to make sure there isn't // any extra string manipulation. if (Trace.IsTracing()) { traceScope = Trace.StartSpan(RpcClientUtil.MethodToTraceString(method)); } ProtobufRpcEngineProtos.RequestHeaderProto rpcRequestHeader = ConstructRpcRequestHeader (method); if (Log.IsTraceEnabled()) { Log.Trace(Thread.CurrentThread().GetId() + ": Call -> " + remoteId + ": " + method.Name + " {" + TextFormat.ShortDebugString((Message)args[1]) + "}"); } Message theRequest = (Message)args[1]; ProtobufRpcEngine.RpcResponseWrapper val; try { val = (ProtobufRpcEngine.RpcResponseWrapper)client.Call(RPC.RpcKind.RpcProtocolBuffer , new ProtobufRpcEngine.RpcRequestWrapper(rpcRequestHeader, theRequest), remoteId , fallbackToSimpleAuth); } catch (Exception e) { if (Log.IsTraceEnabled()) { Log.Trace(Thread.CurrentThread().GetId() + ": Exception <- " + remoteId + ": " + method.Name + " {" + e + "}"); } if (Trace.IsTracing()) { traceScope.GetSpan().AddTimelineAnnotation("Call got exception: " + e.Message); } throw new ServiceException(e); } finally { if (traceScope != null) { traceScope.Close(); } } if (Log.IsDebugEnabled()) { long callTime = Time.Now() - startTime; Log.Debug("Call: " + method.Name + " took " + callTime + "ms"); } Message prototype = null; try { prototype = GetReturnProtoType(method); } catch (Exception e) { throw new ServiceException(e); } Message returnMessage; try { returnMessage = prototype.NewBuilderForType().MergeFrom(val.theResponseRead).Build (); if (Log.IsTraceEnabled()) { Log.Trace(Thread.CurrentThread().GetId() + ": Response <- " + remoteId + ": " + method.Name + " {" + TextFormat.ShortDebugString(returnMessage) + "}"); } } catch (Exception e) { throw new ServiceException(e); } return(returnMessage); }