protected int recvRpcResponse(Type type, ref object response) { try { RpcStatus status = new RpcStatus(); object reference = status; _channel.extractMessage(status.GetType(), ref reference); status = (RpcStatus)reference; if (status.status != RpcStatus.Status.OK) { throw new RpcLayerException(status.status, status.errorDetail); } if (status.appStatus >= 0) { _channel.extractMessage(type, ref response); } else if (_throwOnAppError) { throw new AppLayerException(status.appStatus); } return status.appStatus; } catch (ProtoRpcException e) { throw e; } catch (IOException e) { throw new RpcLayerException(RpcStatus.Status.IO_ERROR, e.Message); } catch (ProtoBuf.ProtoException e) { throw new RpcLayerException(RpcStatus.Status.BAD_RESPONSE, e.Message); } catch (Exception e) { throw new RpcLayerException(RpcStatus.Status.INTERNAL_ERROR, e.Message); } }
public override void ProcessLine(string line, StreamType stream) { base.ProcessLine(line, stream); if (line.Contains("Python exception: ")) { status = RpcStatus.错误; finishMre.Set(); OKETaskException ex = new OKETaskException(Constants.rpcErrorSmr); ex.Data["RPC_ERROR"] = line.Substring(18); throw ex; } else if (line.Contains("RPCOUT")) { frameCount++; job.Progress = 100.0 * frameCount / job.TotalFrame; string[] strNumbers = line.Substring(8).Split(new char[] { ' ' }); int frameNo = int.Parse(strNumbers[0]); double psnr = double.Parse(strNumbers[1]); result.Data.Add((frameNo, psnr)); if (psnr < psnr_threashold) { status = RpcStatus.未通过; } } else if (line.StartsWith("Output ")) { if (status == RpcStatus.等待中) { status = RpcStatus.通过; } finishMre.Set(); } }
protected int recvRpcResponse(Type type, ref object response) { try { RpcStatus status = new RpcStatus(); object reference = status; _channel.extractMessage(status.GetType(), ref reference); status = (RpcStatus)reference; if (status.status != RpcStatus.Status.OK) { throw new RpcLayerException(status.status, status.errorDetail); } if (status.appStatus >= 0) { _channel.extractMessage(type, ref response); } else if (_throwOnAppError) { throw new AppLayerException(status.appStatus); } return(status.appStatus); } catch (ProtoRpcException e) { throw e; } catch (IOException e) { throw new RpcLayerException(RpcStatus.Status.IO_ERROR, e.Message); } catch (ProtoBuf.ProtoException e) { throw new RpcLayerException(RpcStatus.Status.BAD_RESPONSE, e.Message); } catch (Exception e) { throw new RpcLayerException(RpcStatus.Status.INTERNAL_ERROR, e.Message); } }
private void AbortPendingCalls(RpcStatus reason) { this.log.Debug("Aborting all pending calls."); Debug.Assert(Monitor.IsEntered(this.pendingCallsLock), "Pending calls lock must be held."); foreach (var pendingCall in this.pendingCalls) { if (pendingCall.Value.Result == null) { pendingCall.Value.Result = this.ProtocolObjectFactory.CreateRpcResult(); } pendingCall.Value.Result.Status = reason; pendingCall.Value.Status = PendingCallStatus.Cancelled; } }
public static async Task <RpcStatus> GetRpcStatusAsync(this IRPCClient rpc, CancellationToken cancel) { try { var bci = await rpc.GetBlockchainInfoAsync().ConfigureAwait(false); cancel.ThrowIfCancellationRequested(); var pi = await rpc.GetPeersInfoAsync().ConfigureAwait(false); return(RpcStatus.Responsive(bci.Headers, bci.Blocks, pi.Length)); } catch (Exception ex) when(!(ex is OperationCanceledException || ex is TaskCanceledException || ex is TimeoutException)) { Logger.LogTrace(ex); return(RpcStatus.Unresponsive); } }
public Download() { Status = new RpcStatus(); }
public virtual void DoBeforeRequest(string remoteAddr, RpcMessage request) { RpcStatus.BeginCount(remoteAddr); }
public virtual void DoAfterResponse(string remoteAddr, RpcMessage request, object response) { RpcStatus.EndCount(remoteAddr); }
protected override URL doSelect(IList <URL> urls, IInvocation invocation) { int length = urls.Count; // 总个数 int leastActive = -1; // 最小的活跃数 int leastCount = 0; // 相同最小活跃数的个数 int[] leastIndexs = new int[length]; // 相同最小活跃数的下标 int totalWeight = 0; // 总权重 int firstWeight = 0; // 第一个权重,用于于计算是否相同 var sameWeight = true; // 是否所有权重相同 for (int i = 0; i < length; i++) { var url = urls[i]; int active = RpcStatus.GetStatus(url, invocation.MethodInfo.Name).GetActive(); // 活跃数 int weight = url.GetMethodParameter(invocation.MethodInfo.Name, WEIGHT_KEY, DEFAULT_WEIGHT); // 权重 if (leastActive == -1 || active < leastActive) { // 发现更小的活跃数,重新开始 leastActive = active; // 记录最小活跃数 leastCount = 1; // 重新统计相同最小活跃数的个数 leastIndexs[0] = i; // 重新记录最小活跃数下标 totalWeight = weight; // 重新累计总权重 firstWeight = weight; // 记录第一个权重 sameWeight = true; // 还原权重相同标识 } else if (active == leastActive) { // 累计相同最小的活跃数 leastIndexs[leastCount++] = i; // 累计相同最小活跃数下标 totalWeight += weight; // 累计总权重 // 判断所有权重是否一样 if (sameWeight && i > 0 && weight != firstWeight) { sameWeight = false; } } } // assert(leastCount > 0) if (leastCount == 1) { // 如果只有一个最小则直接返回 return(urls[leastIndexs[0]]); } if (!sameWeight && totalWeight > 0) { // 如果权重不相同且权重大于0则按总权重数随机 int offsetWeight = random.Next(totalWeight); // 并确定随机值落在哪个片断上 for (int i = 0; i < leastCount; i++) { int leastIndex = leastIndexs[i]; offsetWeight -= GetWeight(urls[leastIndex], invocation); if (offsetWeight <= 0) { return(urls[leastIndex]); } } } // 如果权重相同或权重为0则均等随机 return(urls[leastIndexs[random.Next(leastCount)]]); }
public RpcMonitor(TimeSpan period, IRPCClient rpcClient) : base(period) { _rpcStatus = RpcStatus.Unresponsive; RpcClient = rpcClient; }
/// <summary> /// Initializes new instance of the <see cref="RpcException"/> class. /// </summary> /// <param name="reason">Error reason.</param> public RpcException(RpcStatus reason) { this.RpcStatus = reason; }
public RpcLayerException(RpcStatus.Status status, string message, Exception innerException) : base("Status = " + status.ToString() + ": " + message, innerException) { this.status = status; }
public RpcLayerException(RpcStatus.Status status) : base("Status = " + status.ToString()) { this.status = status; }
public void Deserialize(BinaryReader reader) { this.Status = (RpcStatus)reader.ReadInt32(); this.ResultData = SerializationHelpers.ReadBytes(reader); }